unixman_again Posted January 19, 2017 Posted January 19, 2017 Is there an easy and cheap method (free would be nice) to record in a central location, the logon time, logoff time and user id of networked W10 PCs?
sted Posted January 19, 2017 Posted January 19, 2017 logon/off scripts depends how much info you want something like echo -------Log user access to Machine-------set mytime=%TIME:~0,-3%echo %username%,%computername%,%mytime%,%date% >> \\server\log$\userlog.txt but its not very searchable and only records logons but you could dump it to a temp file and run a similar script to add time at logoff to that file then dump that temp file into the bigger log (and delete the temp file) so logon echo -------Log user access to Machine-------set mytime=%TIME:~0,-3%echo %username%,%computername%,%mytime%,%date% >> \\server\log$\%computername%.txt logoff echo -------Log user access to Machine-------set mytime=%TIME:~0,-3%echo %mytime%,%date% >> \\server\log$\%computername%.txt copy \\server\log$\%computername%.txt \\server\log$\log.txt havnt tried just thinking out loud 1
LeMarchand Posted January 19, 2017 Posted January 19, 2017 What @sted said, but to csv. Logon: echo LogOn,%COMPUTERNAME%,%USERNAME%,%DATE%,%TIME% >> \\Path\to\LoggingFolder\UsageLog.csv exit Logoff: echo LogOff,%COMPUTERNAME%,%USERNAME%,%DATE%,%TIME% >> \\Path\to\LoggingFolder\UsageLog.csv exit The "Time" looks a bit hinky sometimes, but otherwise seems to work. 1
sted Posted January 19, 2017 Posted January 19, 2017 What @sted said, but to csv. Logon: echo LogOn,%COMPUTERNAME%,%USERNAME%,%DATE%,%TIME% >> \\Path\to\LoggingFolder\UsageLog.csv exit Logoff: echo LogOff,%COMPUTERNAME%,%USERNAME%,%DATE%,%TIME% >> \\Path\to\LoggingFolder\UsageLog.csv exit The "Time" looks a bit hinky sometimes, but otherwise seems to work. thats why i used a mytime variable so that i consistently get the same format or some machines give stupidly precise times that are of no use to anyone 1
LeMarchand Posted January 19, 2017 Posted January 19, 2017 thats why i used a mytime variable so that i consistently get the same format or some machines give stupidly precise times that are of no use to anyone Cheers! So what do the numbers do in mytime=%TIME:~0,-3%?
sted Posted January 19, 2017 Posted January 19, 2017 Cheers! So what do the numbers do in mytime=%TIME:~0,-3%? its an old bit of code i cant remember i think it just caps the time to seconds no tenths hundedths etc 1
LeMarchand Posted January 19, 2017 Posted January 19, 2017 @sted: Tested with my script and it looks like it'll be a great improvement. Added into the "proper" versions. Thank you! @unixman_again: If you do it to csv it saves a step making it sortable. I've found it very useful in identifying machines that aren't being used. 1
ianniow Posted January 19, 2017 Posted January 19, 2017 I use a vbs scirpt one for logon and one for logoff which uses two folders one for computers and one for users and creates name.txt files for each inside these. I can't claim any credit as I got it from edugeek somewhere I think (Long time ago) ' LOGOUT SCRIPT as follows Option Explicit Dim strUserDirectory, strCompDirectory, strDate Dim strUser, strComp Dim strUserFile, strCompFile Dim objWshNtwk, objFSO, objTextFile Set objWshNtwk = WScript.CreateObject("WScript.Network") strUserDirectory = "\\servername\foldername$\Users" strCompDirectory = "\\servename\foldername$\Computers" strDate = Now strUser = (objWshNtwk.UserName) strComp = (objWshNtwk.ComputerName) strUserFile = "\" & CStr(strUser) & ".txt" strCompFile = "\" & CStr(strComp) & ".txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Const ForAppending = 8 ' Username Log Set objTextFile = objFSO.OpenTextFile (strUserDirectory &_ strUserFile, ForAppending, True) objTextFile.WriteLine ("User:" & ", " & strUser & ", " _ & "Logged out of Computer" & ", " & strComp & ", "_ & "at" & ", " & strDate) objTextFile.Close 'computer name Log Set objTextFile = objFSO.OpenTextFile _ (strCompDirectory & strCompFile, ForAppending, True) 'objTextFile.WriteLine (strUser & "," & strComp & "," & strDate) objTextFile.WriteLine ("Computer" & ", " & strComp & ", "_ & "Was logged out of by" _ & ", " & strUser & ", " & "at" & "," & strDate) objTextFile.Close WScript.Quit 3
adrianjones Posted January 23, 2017 Posted January 23, 2017 I use a logon / logoff .bat script: Logon Script: echo Log In %Date% %TIME% %USERNAME% >> \\server\logs$\computers\%COMPUTERNAME%.log echo Log In %Date% %TIME% %COMPUTERNAME% >> \\server\logs$\users\%USERNAME%.log Log Off Script: echo Log Off %Date% %TIME% %USERNAME% >> \\server\logs$\computers\%COMPUTERNAME%.log echo Log Off %Date% %TIME% %COMPUTERNAME% >> \\server\logs$\users\%USERNAME%.log 1
simonw Posted January 23, 2017 Posted January 23, 2017 (edited) Please help, I can't get this to work. I'm trying the simplest of methods and I'm getting no output. My .bat is echo Log In set mytime=%TIME~0,-3% echo %Date% %mytime% %USERNAME% %COMPUTERNAME% >> \\server\user$\LogOn\%COMPUTERNAME%.csv exit So I've added this to the GP for User Config/Windows Settings/Logon and clicked apply I've run a gpupdate, and waited for this to complete but when I logon to a client machine there is no output file. What have I missed? Simon Edited January 23, 2017 by simonw syntax
sted Posted January 23, 2017 Posted January 23, 2017 Please help, I can't get this to work. I'm trying the simplest of methods and I'm getting no output. My .bat is echo Log In set mytime=%TIME~0,-3% echo %Date% %mytime% %USERNAME% %COMPUTERNAME% >> \\server\user$\LogOn\%COMPUTERNAME%.csvexit So I've added this to the GP for User Config/Windows Settings/Logon and clicked apply I've run a gpupdate, and waited for this to complete but when I logon to a client machine there is no output file. What have I missed? Simon what happens if you run the script manually with a pause at the bottom?
simonw Posted January 23, 2017 Posted January 23, 2017 I'm not sure what you mean by pause, im not a coder by any means.
3s-gtech Posted January 23, 2017 Posted January 23, 2017 I'm not sure what you mean by pause, im not a coder by any means. Literally, just put pause at the end of the script. It'll wait for user input before finishing.
LeMarchand Posted January 23, 2017 Posted January 23, 2017 Please help, I can't get this to work. I'm trying the simplest of methods and I'm getting no output. My .bat is echo Log In set mytime=%TIME~0,-3% echo %Date% %mytime% %USERNAME% %COMPUTERNAME% >> \\server\user$\LogOn\%COMPUTERNAME%.csv exit So I've added this to the GP for User Config/Windows Settings/Logon and clicked apply I've run a gpupdate, and waited for this to complete but when I logon to a client machine there is no output file. What have I missed? Simon You may need the commas in for a csv and I think you need to declare the variable first. set mytime=%TIME~0,-3% echo Log In,%Date%,%mytime%,%USERNAME%,%COMPUTERNAME% >> \\server\user$\LogOn\%COMPUTERNAME%.csv exit
simonw Posted January 23, 2017 Posted January 23, 2017 that works for the local machine, thank you. I've had the change the .bat as the mytime was only returning %mytime%. am I being a bit too ambitious wanting to test this on a client machine, as I've tried and got nothing reported to my folder location
sted Posted January 23, 2017 Posted January 23, 2017 if it works logged in as you on a pc but not as a logon script i would guess the pcs account dosent have read/write access to your server location (either give that share authenticated user modify of domain computers modify permissions)
simonw Posted January 23, 2017 Posted January 23, 2017 (edited) I spotted the error for the %mytime%, I'd missed a colon after TIME.... set mytime=%TIME:~0,-3% echo LogOn echo %Date% %mytime% %USERNAME% %COMPUTERNAME% >> \\\LogOn\%COMPUTERNAME%.csv exit Its working without commas for .csv output too. Now to hope it works on the client machines.... Edited January 23, 2017 by simonw syntax
Chris_RM Posted January 23, 2017 Posted January 23, 2017 Hello, RM has recently developed a free tool called RM inform that accurately monitors the logon times for machines on a Windows network, reporting back to a central console that the network team can use. Alongside, logon times it also monitors other things such as what machines are / aren't being used, what specification they are and the installed software. RM Inform is currently in it's initial release, with new features on the roadmap for the future. RM Inform - School IT monitoring and reporting PM me if you have any questions or want to talk through the detail. Thanks, Chris
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