Monday 23 September 2013

How to shutdown a computer in vbscript?


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

'Here you can specify name of computer you want to  shutdown.....
'. 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

No comments:

Post a Comment

Total Pageviews