Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 20th, 2008, 4:49 PM   #1
bscr
beginning netwrk *****
 
Join Date: Jun 2008
Posts: 1
Rep Power: 0 bscr is on a distinguished road
Question Batch file problems

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
bscr is offline   Reply With Quote
Old Jun 27th, 2008, 10:08 AM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
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?"
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC