-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathshutdown.vbs
More file actions
39 lines (31 loc) · 1.09 KB
/
Copy pathshutdown.vbs
File metadata and controls
39 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
On Error Resume Next
Do While True
currentHour = Hour(Now)
currentMinute = Minute(Now)
currentSecond = Second(Now)
If currentHour >= 1 And currentHour <= 5 Then
firstCPUUsage = GetCPUUsage()
' Pause for 20 second before getting CPU usage data for 2nd time
WScript.Sleep 20000
secondCPUUsage = GetCPUUsage()
If firstCPUUsage < 10 And secondCPUUsage < 10 Then
' Pause for 100 second before shutting down
WScript.Sleep 100000
ShutdownComputer()
End If
End If
' Pause for 10 second before checking again
WScript.Sleep 10000
Loop
Function GetCPUUsage()
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Processor Where Name = '_Total'")
For Each objItem in colItems
cpuUsage = objItem.PercentProcessorTime
Next
GetCPUUsage = cpuUsage
End Function
Sub ShutdownComputer()
Set objShell = CreateObject("WScript.Shell")
objShell.Run "shutdown /s /t 0", 0, True
End Sub