Solved

Restart Machine?

Posted on 2003-12-08
6
395 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
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!

 
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month10 days, 4 hours left to enroll

623 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