General discussion

Locked

Last Rebooted

By BlackDiamond ·
Hey,

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

This conversation is currently closed to new comments.

19 total posts (Page 2 of 2)   Prev   01 | 02
Thread display: Collapse - | Expand +

All Comments

Collapse -

by neilb@uk In reply to

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.

Collapse -

by neilb@uk In reply to

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

Collapse -

by neilb@uk In reply to

'
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

Collapse -

by BlackDiamond In reply to

Hey,

Thanx for you help that works great.

Collapse -

by BlackDiamond In reply to Last Rebooted

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

Collapse -

by BlackDiamond In reply to Last Rebooted

Point value changed by question poster.

Collapse -

by BlackDiamond In reply to Last Rebooted

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.

Collapse -

by BlackDiamond In reply to Last Rebooted

Point value changed by question poster.

Collapse -

by BlackDiamond In reply to Last Rebooted

This question was closed by the author

Back to Desktop Forum
19 total posts (Page 2 of 2)   Prev   01 | 02

Related Discussions

Related Forums