User Rating: 0 / 5

Star inactiveStar inactiveStar inactiveStar inactiveStar inactive
 

The following scripts can be used to count the number of times a computer has been turned on.

It queries the 'Sytem' event log for Event 12 which is 'The operating system started at system time ‎2011‎-‎05‎-‎16T05:28:24.359599800Z'

It then counts the number of Event 12's and echos the number.

The second script can be used on remote computers as long as you have the appropriate Administrator rights on the machine.

To use the scripts you wil need to copy into a text document and save the file is a .vbs extension.

You can also download from here

 

 Count number of times computer has turned on:

Output:

VBS-CountStarted2

VBS Code:

count = 0
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'System'" _
        & " and EventCode = '12'")

For Each objEvent in colLoggedEvents
    count = count + 1

Next

wscript.echo "Number of times operating system has started:   " & count

 

Remotely count number of times computer has turned on:

Output:

VBS-CountStarted1

VBS-CountStarted2

VBS Code:

count = 0
strComputer=InputBox ("Enter the network name for the remote computer")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'System'" _
        & " and EventCode = '12'")

For Each objEvent in colLoggedEvents
    count = count + 1

Next

wscript.echo "Number of times operating system has started:   " & count

Add comment

All questions, comments or feedback are welcome. However we ask that you refrain from leaving unconstructive messages.
If you are having issues with the content covered we ask that you ensure you have followed the steps as detailed, then in your comment state THE STEP NUMBER which you are stuck at and any other relevant technical information (Mac or Windows, operating system version, Internet browser etc.).
We would like to help where possible, and this helps us help you! :)

Please note: due to an increase of comment spam moderation has been enabled. Your comment will be moderated before being published. This typically takes 24 hours.


Security code
Refresh