![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
beginning netwrk *****
Join Date: Jun 2008
Posts: 1
Rep Power: 0
![]() |
Hi all!
Here is my problem: I'm trying to create a batch file that needs to needs to record the login and logoff times of users. This needs to be recorded between 5PM and 10 PM. At other times, no information needs to be gathered, just between those hours. Also, the file that is created will need to be deleted after a week. What I have so far: This batch file runs first: ::== 5to9.bat @echo off setLocal EnableDelayedExpansion set run=n for /f "tokens=1 delims=:" %%T in ('echo %TIME%') do ( set T=%%T if !T! >17 set run=y if !T! < 22 set run=y ) if !run! ==y login.bat ::== DONE After this is checked, this batch file should be triggered: echo logon,User:,%username%,Computer:,%computername%,Date:,%date%,Time:,%time% >>C:\auditlog\%username%.csv Here is the problem: The logging of the users runs by itself, but not when I run the first batch file. Also, how would I go about adding code to delete the created file after a week? Any help would be greatly appreciated!! Stefan |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4
![]() |
Re: Batch file problems
I have half an answer - hopefully you're still waiting for one! It's been a very long time since I wrote a batch file that did more than start two or three programs then quit (more than that and I tend to resort to Tcl, or VBScript/JScript on Windows), but I seem to remember that you need to use the 'call' command to call another batch file:
if !run! ==y call login.bat I don't have a Windows machine to try it on, but that might be part of the answer. I did give a few moments of thought to your other problem (deleting the files after a week) but I got that 'Oh God, give me a real shell' feeling and couldn't get past it - this is the main reason I don't write batch files any more! The call thing I'm not 100% sure of because if I remember correctly, leaving it out didn't stop the called script running, it just stopped execution from returning to the first script. Hopefully this is of some use to you anyway!
__________________
"I'm not a genius. Why do I have to suffer?" |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| c++ code to read from batch file | cueballr | C++ | 21 | Nov 2nd, 2007 9:06 PM |
| Create a new batch file | Steiner | Bash / Shell Scripting | 7 | Jul 12th, 2006 5:20 PM |
| File stream problems | Dan | C++ | 13 | Sep 21st, 2005 8:05 AM |
| Embedding a batch file into a C++ app | vynkz | C++ | 22 | May 18th, 2005 8:59 PM |
| Update registry key value via batch file | dpasswat | Other Scripting Languages | 1 | Mar 17th, 2005 10:45 AM |