Thursday, January 3, 2019

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



0 comments:

Post a Comment

Blog Archive

Translate

Popular Posts

Total Pageviews

Blog Archive