Dim
testResult AsSingle
Dim WMIServiceObject, ComputerObject AsObject
'Now get some privileges
WMIServiceObject = GetObject(
"Winmgmts:{impersonationLevel=impersonate,(Debug,Shutdown)}")
ForEach ComputerObject In WMIServiceObject.InstancesOf("Win32_OperatingSystem")
testResult = ComputerObject.Win32Shutdown(2 + 4, 0)
'reboot
'testResult = ComputerObject.Win32Shutdown(0, 0) 'logoff
' testResult = ComputerObject.Win32Shutdown(8 + 4, 0) 'shutdown
If testResult <> 0 Then
MsgBox("Sorry, an error has occurred while trying to perform selected operation")
Else
'Operation selected in statement above if condition would be carried out
EndIf
Next