Several of my coworkers and I have created a script that gives us some info on remote computers we are working on. Currently one of the pieces of information we need is finding out when a remote computer's uptime. We are using the code "Systeminfo /S %computername% | Find "Up Time""
For reasons I won't get into here this script is only working on about 65% of the computers we are testing. The other 35% come back with a "System Up Time: N/A" status. After searching Google, we believe this to be a problem with the WMI service of the computers.
With that said we need an alternate way of getting this information. We are aware there are plenty of third party tools to do this but due to company policy we can only use scripts.
Does anyone have any thoughts on how to get a systems up time other than the systeminfo command in Windows XP?
Need a way of finding out when a computer last booted
Moderator: DosItHelp
Re: Need a way of finding out when a computer last booted
Only an idea ...
Save as "uptime.vbs":
Call as follows:
Regards
aGerman
Save as "uptime.vbs":
Code: Select all
On Error Resume Next
strComputer = WScript.Arguments(0)
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colEvents = oWMI.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' and EventCode = '6005'")
For Each singleEvent In colEvents
timestamp = singleEvent.TimeWritten
Exit For
Next
WScript.Echo FormatDateTime(Now - CDate(DateSerial(Left(timestamp, 4), Mid(timestamp, 5, 2), _
Mid(timestamp, 7, 2)) & " " & TimeSerial(Mid(timestamp, 9, 2), _
Mid(timestamp, 11, 2), Mid(timestamp, 13, 2))))
Call as follows:
Code: Select all
@echo off &setlocal
for /f "delims=" %%a in ('cscript //nologo uptime.vbs "%computername%"') do echo %%a
pause
Regards
aGerman
Re: Need a way of finding out when a computer last booted
Thanks. I will give that a try and see if it works out. The other idea I have been reading about online is using the date and time stamp of the Windows pagefile. Assuming it is in the same location on each computer I would think this would work. Does the pagefile date and time change for any other reason than a computer boot? I have only checked this out on a few machines but it seems accurate.