Solved

Restart Machine?

Posted on 2003-12-08
6
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

710 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