Link to home
Start Free TrialLog in
Avatar of B_Dorsey
B_Dorsey

asked on

Restart Machine?

Is it possible to write a script that checks a webpage for either an error or if it doesnt bring up anything ..etc.etc.. that it will jsut restart the machine?

Thanks
Bill D
Avatar of mccainz2
mccainz2

script or a VB application ?

the following will restart the machine , works (with minor mods in VB and VB script)

Private Sub Command1_Click()
 
    Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}" & _
                         "//./root/cimv2").ExecQuery("SELECT * FROM " & _
                         "Win32_OperatingSystem WHERE Primary = true")

    ianswer = MsgBox("Shut Down Windows? -Warning- Save data first!", _
                  vbQuestion + vbOKCancel, _
                 "Shut Down")

    If ianswer = vbOK Then 'If OK, shut down

    For Each OpSys In OpSysSet
      outParam = OpSys.Shutdown

      If Err.Number <> 0 Then
         WScript.echo "Error number: " & Err.Number & _
                        vbNewLine & _
                       "Description: " & Err.Description
      End If

    Next

    Else                   ' user selected cancel
       MsgBox "Operation canceled"
    End If

End Sub
ASKER CERTIFIED SOLUTION
Avatar of mccainz2
mccainz2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
BTW: the above code was tested on an XP machine .... If you have trouble getting it to compile on a 2k box you may need to download and install the WMI redistributable... I'll hunt up the link in a few.
Ive been able to reduce the lines of code some more....using  *.InstancesOf lets me workaround the WMI scripting Query.....

Set OSSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}").InstancesOf("Win32_OperatingSystem")
   
    For Each System In OSSet
            System.Shutdown
    Next

Avatar of B_Dorsey

ASKER

Thanks mccainz2

It shuts down, now I just gotta get it to do it when I want it too.

Thanks again

Bill D