Set objSystemSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}").InstancesOf("Win32_OperatingSystem")
For Each objSystem In objSystemSet
objSystem.Win32Shutdown 2
Next
▼ Windowsをシャットダウンさせる
Set objSystemSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}").InstancesOf("Win32_OperatingSystem")
For Each objSystem In objSystemSet
objSystem.Win32Shutdown 8
Next
'現在の時刻 HH:MM:SS を数値で取得 01時02分30秒 → 010230
Dim str As String
str = Format(Now, "HH:MM:ss")
Dim H As Long
H = CLng(Mid(str, 1, 2) & Mid(str, 4, 2) & Mid(str, 7, 2))
'時間になったらパソコンの電源を落とす
If H = CLng("191000") Then
Dim objSystemSet, objSystem As Object
Set objSystemSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}").InstancesOf("Win32_OperatingSystem")
For Each objSystem In objSystemSet
objSystem.Win32Shutdown 8
Next
End If