Tuesday, 27 January 2015

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:

*****************************************
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

*********************************************


If you want to check a remote machine here's the script:

***************************************************
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
**********************************************

0 commenti:

Post a Comment

Give me you feedback!