Monday 23 September 2013

How to Restart a machine in vbscript?


'Warning - if you run this script, your computer will reboot/restart

'Here you can specify name of computer you want to restart.....
'. 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 restart.
For Each Os in colOperatingSystems
    Os.Reboot()
Next

No comments:

Post a Comment

Total Pageviews