Solved

Restart Machine?

Posted on 2003-12-08
6
386 Views
Last Modified: 2010-05-01
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
Comment
Question by:B_Dorsey
  • 5
6 Comments
 
LVL 5

Expert Comment

by:mccainz2
ID: 9900348
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
 
LVL 5

Accepted Solution

by:
mccainz2 earned 500 total points
ID: 9900393
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
 
LVL 5

Expert Comment

by:mccainz2
ID: 9900433
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:mccainz2
ID: 9900840
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9901565
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
 
LVL 14

Author Comment

by:B_Dorsey
ID: 9906594
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now