Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

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
0
B_Dorsey
Asked:
B_Dorsey
  • 5
1 Solution
 
mccainz2Commented:
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
0
 
mccainz2Commented:
Heres a rough app I did that shuts down on a navigate error from a webbrowser control ...

Pure VB application...THis thing is really no fun to test!

Private Sub shutDown()
 
    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

Private Sub Command2_Click()
    With WebBrowser1
        .Navigate Text1.Text
    End With
End Sub

Private Sub WebBrowser1_NavigateError(ByVal pDisp As Object, URL As Variant, Frame As Variant, StatusCode As Variant, Cancel As Boolean)
    shutDown
End Sub
0
 
mccainz2Commented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mccainz2Commented:
0
 
mccainz2Commented:
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

0
 
B_DorseyAuthor Commented:
Thanks mccainz2

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

Thanks again

Bill D
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now