Discussion Locked

Last Rebooted

0 helpful
19 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hey,

Is there any way or any programs out that will allow you to remotely see when a PC/Server was last rebooted?

19 replies

by bfilmfan

Assuming this is Microsoft:

Workstation:

net statistics workstation | more

Server:

net statistics server | more

Enjoy.

by blackdiamond

Hey,

Yes it is Windows, Sorry.

That appears to show me the stats for the system I am on. It could be that I am doing it wrong which would not be a first for me.

Maybe I did not phrase it right in the main question.

I am on my system, we'll call it BD1
I want to be able to look at a system called BD2 in a different department and see when it was last rebooted.

Thanx

by 3xp3rt

With net statistics command you can see if the connection with server was broken but you don't know when. For more informations you need to see the server's events. A solution can bee if you make an application for monitoring the connection with server, and notify all the events.

by Member 25348569

Have a little vbscript

sServerName = "DC-01" ' obviously, whatever your server's called

Set objWMIService = GetObject ("winmgmts:\\" & sServerName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dOldLaststart = WMIDateStringToDate(objOS.LastBootUpTime)
Next
wscript.echo "Previous boot up date and time was " & dOldLastStart

wscript.quit

Function WMIDateStringToDate(dBoot)
WMIDateStringToDate = DateAdd("n",cInt(right(dBoot,4)) * -1, _
CDate(Mid(dBoot, 7, 2) & "/" & Mid(dBoot, 5, 2) & "/" & _
Left(dBoot, 4) & " " & Mid (dBoot, 9, 2) & ":" & _
Mid(dBoot, 11, 2) & ":" & Mid(dBoot, 13, 2)))
End Function

by Member 25348569

Nope. I'll fix it now. You need to change the script according to my second comment as it's set to convert an English DD/MM/YY string to a date and you need MM/DD/YY.

You should change your script so that Line 14 reads:
CDate(Mid(dBoot,5,2) & "/" & Mid(dBoot,7,2) & "/" & _

This swapping of 5 and 7 swaps the DD and MM around so the date string doesn't go out of range.

For instance, my next birthday is 23/02/2006 in English notation and that would cause an error if I tried to convert that string to a US date.

Good luck.

by Member 25348569

I don't think that you cut-and-pasted my script properly.

In my original, the fourth bit of the composite line in the function (it's really all one long line split by underscores) should read
Mid(dBoot,11,2) & ":" & Mid(dBoot,13,2)))
and not
Mid(dBoot,5,2) & "/" & Mid(dBoot,7,2)))

I just didn't read your version properly so I didn't spot it earlier! D'Oh.

The whole date conversion function should read, for your US dates,

Function WMIDateStringToDate(dBoot)
WMIDateStringToDate = DateAdd("n",cInt(right(dBoot,4)) * -1, _
CDate(Mid(dBoot,5,2) & "/" & Mid(dBoot,7,2) & "/" & _
Left(dBoot,4) & " " & Mid (dBoot,9,2) & ":" & _
Mid(dBoot,11,2) & ":" & Mid(dBoot,13,2)))
End Function

by Member 25348569

'
sServerName = inputbox("Type the damn name!!")

Set objWMIService = GetObject("winmgmts:\\" & sServerName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dOldLaststart = WMIDateStringToDate(objOS.LastBootUpTime)
Next
wscript.echo "Previous boot up date and time was " & dOldLastStart

wscript.quit

Function WMIDateStringToDate(dBoot)
WMIDateStringToDate = DateAdd("n",cInt(right(dBoot,4)) * -1, _
CDate(Mid(dBoot,5,2) & "/" & Mid(dBoot,7,2) & "/" & _
Left(dBoot,4) & " " & Mid (dBoot,9,2) & ":" & _
Mid(dBoot,11,2) & ":" & Mid(dBoot,13,2)))
End Function

by blackdiamond

Hey,

Seems like we may be on the right track. :-))

I am not much of a script writer so I am not sure what I should change. The script is not quite working, I get this error

Line: 14
Char: 1
Error: Type mismatch: 'CDate'
Code: 800A000D
Source:Microsoft VBScript runtime error

Here is my script.

sServerName = inputbox("Insert The Damn Name!!")

Set objWMIService = GetObject ("winmgmts:\\" & sServerName & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dOldLaststart = WMIDateStringToDate(objOS.LastBootUpTime)
Next
wscript.echo "Previous boot up date and time was " & dOldLastStart

wscript.quit

Function WMIDateStringToDate(dBoot)
WMIDateStringToDate = DateAdd("n",cInt(right(dBoot,4)) * -1, _
CDate(Mid(dBoot, 7, 2) & "/" & Mid(dBoot, 5, 2) & "/" & _
Left(dBoot, 4) & " " & Mid (dBoot, 9, 2) & ":" & _
Mid(dBoot,5,2) & "/" & Mid(dBoot,7,2)))
End Function

by blackdiamond

Hey,

Made the last change you suggested and nada. It pops up the same error.

I appreciate you efforts in this. Have bumped up the points again.

This discussion is closed to new replies.