laura Posted April 26, 2006 Posted April 26, 2006 Hello allI would like to run script to log session uptime before windows is shutdowning or restarting. The script is something like this:@echo. >> %systemdrive%\logs\uptime.log@echo %date:~2,8% %time:~0,8% >> %systemdrive%\logs\uptime.log@systeminfo | find "Up Time" >> %systemdrive%\logs\uptime.logOr maybe anybody knows the program which could do this task...
cluberti Posted April 26, 2006 Posted April 26, 2006 Start > Run > gpedit.mscComputer Configuration > Windows Settings > Scripts > Shutdown
Yzöwl Posted April 26, 2006 Posted April 26, 2006 (edited) You could also use a vbscript, there's a lot more code, but it would work much faster!uptime.vbsOption ExplicitDim strComputer, strDirectory, strFileDim objFSO, objFolder, objTextFile, objFile, objWMIService, objOSDim colOperatingSystems, intSystemUptime, TimedAt, M, S, H, DstrComputer="."'log file location and namestrDirectory="C:\Logs"strFile="\uptime.log"'On Error Resume NextSet objFSO=CreateObject("Scripting.FileSystemObject")If objFSO.FolderExists(strDirectory) Then Set objFolder=objFSO.GetFolder(strDirectory)Else Set objFolder=objFSO.CreateFolder(strDirectory)End IfIf objFSO.FileExists(strDirectory &strFile) Then Set objFolder=objFSO.GetFolder(strDirectory)Else Set objFile=objFSO.CreateTextFile(strDirectory &strFile)End If Set objFile=nothing : Set objFolder=nothingSet objTextFile=objFSO.OpenTextFile(strDirectory &strFile, 8, True)Set objWMIService=GetObject("winmgmts:\\" &strComputer &"\root\cimv2")Set colOperatingSystems=objWMIService.ExecQuery _ ("Select * From Win32_PerfFormattedData_PerfOS_System")For Each objOS in colOperatingSystems intSystemUptime=Int(objOS.SystemUpTime) TimedAt=FormatDateTime(Date(),2) &", " &FormatDateTime(Time(),4) UpTime(intSystemUptime) NextFunction UpTime(S) M=S\60 : S=S mod 60 : H=M\60 : M=M mod 60 : D=H\24 UpTime=D &" Days, " &H &" Hours, " &M &" Minutes" objTextFile.WriteLine(TimedAt &", " &UpTime)End FunctionobjTextFile.CloseWScript.QuitI have set lines 8 and 9 to suit your first post but they should be all you would need to change if anything.The output will all be on one line [date, time without seconds, Uptime (days, hours, minutes)]uptime.log26/04/2006, 22:47, 0 Days, 13 Hours, 53 Minutes<Edit>WMIC script replaced with the VBscript above</Edit> Edited April 26, 2006 by Yzöwl
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now