Thursday, January 3, 2019


How to shutdown a computer in VBScript?


'Warning - if you run this script, your computer will shut down

'Here you can specify name of the computer you want to  shut-down.....
'. means local computer
strComputer = "."

'create WMI object

Set objWMIService = GetObject_
    ("winmgmts:{impersonationLevel=impersonate,(Shutdown)}\\" & _
        strComputer & "\root\cimv2")

'Get the reference of all operating systems in your machine using Win32_OperatingSystem


Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")


'Enumerate each OS and shut down .
For Each objOperatingSystem in colOperatingSystems
    objOperatingSystem.Win32Shutdown(1)
Next




0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

Blog Archive