Mike-j Posted February 27, 2008 Posted February 27, 2008 I am running the following script on the server from a gpo to log user activity, I copied the script from this site and adjusted to suit our domain. However I have issues with the date function of the script any help would be appreciated. Copy of output file for Geo_office 022008,1334,yneeve 022008,1515,yneeve 022008,1521,yneeve 022008,0901,yneeve 022008,0500,Administrator 02272008 ,0502 AM,Administrator 022008,0505,Administrator 022008,0505,Administrator The date is not correct on the first 5 entries, if I log on and to the machine and change the date settings to English united states all is well as seen on line 5. This is qualified by lines 7 and 8 not working once I have changed the date settings back to uk. What is the correct format for the fist 2 lines of the script to extract the correct time from the local computer? Audit Script for /f "tokens=1,2,3* delims=/ " %%a in ('date /t') do set date=%%b%%c%%d for /f "tokens=1,2 delims=:" %%a in ('time /t') do set time=%%a%%b echo %date%,%time%,%username% >> \\server2\ipstats\logs\computer\%computername%.txt echo %date%,%time%,%computername% >> \\server2\ipstats\logs\user\%username%.txt echo %logonserver% >> \\server2\ipstats\logs\logon\%computername%.txt echo %time% %username% > \\server2\ipstats\logs\users\%computername%.txt ipconfig | find "IP Address" > \\server2\ipstats\logs\ips\%computername%.txt ipconfig | find "IP Address" > \\server2\ipstats\logs\ips\%computername%.txt Kind Regards Mike
srochford Posted February 27, 2008 Posted February 27, 2008 could be wrong but I don't think you can deal with this in a batch file. I think the "time" command will always show what it thinks is local time so if some of your machines are configured US and some UK then you will get it mixed up. The "for /f" bit is telling it to split the string at the "/" but has no way of knowing if it's getting 27/02/2008, 02/27/2008 etc. I always do this kind of thing in vbscript and strip out the day, month, year and then stick them back together appropriately: sDate=year(now) & right("0" & month(now),2) & right("0" & day(now),2) - replace "now" with a variable for the relevant date if you're not interested in the current date/time. This way you always end up with yyyymmdd and it makes it easier to process!
Mike-j Posted February 27, 2008 Author Posted February 27, 2008 Great thanx will sort that out, i will use vb thanx for the advice will keep you posted. regards Mike
Mike-j Posted February 28, 2008 Author Posted February 28, 2008 great thanx for putting me in the right direction, now using vb script below works great, had to mess around a bit not being a natural at scripting, once again thank you! call logger public sub logger() dim filesys, filetxt, uservar set WshNetwork = Createobject("WScript.Network") Set objNetwork = Wscript.CreateObject("Wscript.Network") Set filesys = CreateObject("Scripting.FileSystemObject") on error resume next computername = objNetwork.ComputerName Const ForReading = 1, ForWriting = 2, ForAppending = 8 uservar = objNetwork.UserName Set filetxt = filesys.OpenTextFile("\\server2\ipstats\logs\computer\" & computername & ".txt", ForAppending, True) filetxt.WriteLine(Date & ": " & Time & ": " & uservar & " logged on to " & computername) filetxt.Close Set filetxt = filesys.OpenTextFile("\\server2\ipstats\logs\user\" & uservar & ".txt", ForAppending, True) filetxt.WriteLine(Date & ": " & Time & ": " & uservar & " logged on to " & computername) filetxt.Close end sub 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now