VBS Script – Count Number of times computer has turned on

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