• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

Shutdown Script with Progress Bar

I found this code on this site and it would be great if it worked.  But for me it does not.  I'm looking for a Shutdown script that will give uers a progress bar countdown, and/or a cancel button.  Any help is appreciated
Dim oProgressBar
Dim sComputer
Dim oWMIService
Dim cServices
Dim oService
Dim numSeconds
Dim i

'Set the number of seconds before reboot
numSeconds = 10

Set oProgressBar = New IEProgressBar
oProgressBar.sTitle = "System Reboot"
oProgressBar.sHeader = "System will reboot in " & numSeconds & " seconds.  Please save your work..."
oProgressBar.sHeader2 = "Closing this window will result in an immediate reboot."
oProgressBar.sFooter = "Rebooting..."
oProgressBar.bSilent = True
oProgressBar.DisplayHeader

For i = 0 to numSeconds
    WScript.Sleep(1000) ' Slow down only necessary for example
    If Err Then
      PerformReboot
      WScript.Quit
    End If
    oProgressBar.Tick numSeconds - i
Next

oProgressBar.Complete

PerformReboot

WScript.Quit()

Private Sub PerformReboot()
      Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true") 
      for each OpSys in OpSysSet 
             opsys.Win32ShutDown 2,0
      next
End Sub


'Begin IEProgressBar Class
Class IEProgressBar

Private oExplorer        ' Internet Explorer object
Private oDocument        ' IE Document object
Private iCounter        ' Counts # of ticks on progress bar
Private oWshShell        ' WshShell object
Public sTitle            ' Title of IE object
Public sHeader            ' Header comment of progress bar
Public sHeader2
Public sFooter            ' Trailing comment when bar complete
Public bSilent            ' Silent mode disables OK button at end of bar
Public iWidth            ' Width if IE dialog - Set before DisplayHeader
Public iHeight            ' Height of IE dialog - Set before DisplayHeader

Private Sub Class_Initialize
    iWidth = 400            ' default Width
    iHeight = 200            ' default Height
    sTitle = "Progress Bar"    ' default Title
    sHeader = "Starting"    ' default Header
    sFooter = "Done"        ' default Footer
    bSilent = False            ' default Silent mode
    Set oWshShell = CreateObject("Wscript.Shell")
    Set oExplorer = WScript.CreateObject _
     ("InternetExplorer.Application", "IE_")
    oExplorer.Navigate "about:blank" 
    oExplorer.ToolBar = False
    oExplorer.StatusBar = False
    oExplorer.Width = iWidth
    oExplorer.Height = iHeight
                
    Do While (oExplorer.Busy)    ' Wait untill IE loads
        Wscript.Sleep 100
    Loop
    
    iCounter = 0
End Sub

Private Sub Class_Terminate
    If IsObject( oDocument ) Then Set oDocument = Nothing
    If IsObject( oExplorer ) Then Set oExplorer = Nothing
    If IsObject( oWshShell ) Then Set oWshShell = Nothing
End Sub

Private Sub IEDoc(sFunc, sHTML)
    On Error Resume Next
    Select Case sFunc
        Case "Open"
            oDocument.Open
        Case "Close"
            oDocument.Close
        Case "Writeln"
            oDocument.Writeln(sHTML)
        Case "Write"
            oDocument.Write(sHTML)
        Case Else
    End Select
End Sub

Public Sub DisplayHeader
    oExplorer.Width = iWidth
    oExplorer.Height = iHeight
    Set oDocument = oExplorer.Document
    Call IEDoc("Open",Null)
    Call IEDoc("Writeln","<script language=""VBScript"">")
    Call IEDoc("Writeln","Sub Window_OnLoad()")
    Call IEDoc("Writeln","theleft = (screen.availWidth - document.body.clientWidth) / 2")
    Call IEDoc("Writeln","thetop = (screen.availHeight - document.body.clientHeight) / 2")
    Call IEDoc("Writeln","window.moveTo theleft,thetop")
    Call IEDoc("Writeln","End Sub")
    Call IEDoc("Writeln","</script>")
    Call IEDOc("Close",Null)

    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
    Call IEDoc("Writeln","<body bgcolor='white'>")
    Call IEDoc("Writeln","<font color=black face=""Arial"">")
    Call IEDoc("Writeln",sHeader & " " & sHeader2 & "<p>")
    Call IEDoc("Writeln","</font>")
    Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">")

    
    oExplorer.Visible = True
    Do Until oWshShell.AppActivate(sTitle)        ' Wait till focus given
        Wscript.Sleep 100
    Loop 
End Sub

Public Sub Tick(secondsRemaining)
      Dim j
        Call IEDOc("Close",Null)
        Call IEDoc("Open",Null) 
        Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
        Call IEDoc("Writeln","<body bgcolor='white'>")
        Call IEDoc("Writeln","<font color=black face=""Arial"">")
        Call IEDoc("Writeln","System will reboot in " & secondsRemaining & " seconds.  Please save your work... " & sHeader2 & "<p>")
      Call IEDoc("Writeln","</font>")
      Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">")

    iCounter = iCounter + 1
    for j = 1 to iCounter
      Call IEDoc("Write","n")
    Next

    If iCounter = 10 Then
      iCounter = 0
    End If
End Sub

Public Sub Complete
    Call IEDOc("Close",Null)
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
    Call IEDoc("Writeln","<body bgcolor='white'>")
    'Call IEDoc("Writeln","<font color=black face=""Arial"">")
    'Call IEDoc("Writeln",sHeader & "<p>")
    Call IEDoc("Writeln","<br><p><p>" & sFooter)
    Call IEDoc("Writeln","</font>")
    
    Call IEDoc("Writeln","<script language=""VBScript"">")
    Call IEDoc("Writeln","Public InputComplete")
    Call IEDoc("Writeln","Sub buttonOK_OnClick")
    Call IEDoc("Writeln","        InputComplete = 1 ' User input is ready")
    Call IEDoc("Writeln","End Sub")
    Call IEDoc("Writeln","</script>")
    
    Call IEDoc("Writeln","<form name=""ParameterForm"">")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","<input type=""button"" name=""ButtonOK"" value=""OK""><br>")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","</form>")
    Call IEDoc("Writeln","</body></html>")
    Call IEDoc("Close",Null)
        
    On Error Resume Next
    If Not bSilent Then
        Do ' Waiting for OK button
            Wscript.Sleep 100
        Loop While (oExplorer.document.script.InputComplete = 0)
    End If
    If Err Then
        Err.Clear()
        Wscript.quit()
    End If
    On Error Goto 0
    
    oExplorer.Quit 
End Sub

End Class

Open in new window

0
beckman55
Asked:
beckman55
  • 5
  • 5
  • 2
  • +1
1 Solution
 
RobSampsonCommented:
Hi there.  When I run it, it appears that it is not detecting the new window because of the IE branding in the window title.

Change your
DisplayHeader
public sub procedure with the code below and see if it works then.  You should see red squares appears on the IE window.

Regards,

Rob.
Public Sub DisplayHeader 
    Dim sIETitle
    oExplorer.Width = iWidth 
    oExplorer.Height = iHeight 
    Set oDocument = oExplorer.Document 
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<script language=""VBScript"">") 
    Call IEDoc("Writeln","Sub Window_OnLoad()") 
    Call IEDoc("Writeln","theleft = (screen.availWidth - document.body.clientWidth) / 2") 
    Call IEDoc("Writeln","thetop = (screen.availHeight - document.body.clientHeight) / 2") 
    Call IEDoc("Writeln","window.moveTo theleft,thetop") 
    Call IEDoc("Writeln","End Sub") 
    Call IEDoc("Writeln","</script>") 
    Call IEDOc("Close",Null) 
 
    Call IEDoc("Open",Null)  
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>") 
    Call IEDoc("Writeln","<body bgcolor='white'>") 
    Call IEDoc("Writeln","<font color=black face=""Arial"">") 
    Call IEDoc("Writeln",sHeader & " " & sHeader2 & "<p>") 
    Call IEDoc("Writeln","</font>") 
    Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">") 
    
    Dim oReg
    Dim sIEBranding
    Dim oShell
    Set oShell = CreateObject("WScript.Shell")
    sIEBranding = oShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\Window Title")
    oExplorer.Visible = True
    sIETitle = "http:// - " & sTitle & " - " & sIEBranding
    'MsgBox "Looking for " & sIETitle
    Do Until oWshShell.AppActivate(sIETitle)        ' Wait till focus given 
        Wscript.Sleep 100
    Loop  
End Sub

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
beckman55Author Commented:
I pasted your code in but I get this error now:

Line: 129
Char: 5

Error:  Unable to open the registry key "HKCU\Software\Microsoft\Internet Explorer\Main\Window Title" for reading
Code: 80070002
Source: WshShell.RegRead
0
 
beckman55Author Commented:
Sorry here's the new code:
Dim oProgressBar
Dim sComputer
Dim oWMIService
Dim cServices
Dim oService
Dim numSeconds
Dim i

'Set the number of seconds before reboot
numSeconds = 20

Set oProgressBar = New IEProgressBar
oProgressBar.sTitle = "System Reboot"
oProgressBar.sHeader = "System will reboot in " & numSeconds & " seconds.  Please save your work..."
oProgressBar.sHeader2 = "Closing this window will result in an immediate reboot."
oProgressBar.sFooter = "Rebooting..."
oProgressBar.bSilent = True
oProgressBar.DisplayHeader

For i = 0 to numSeconds
    WScript.Sleep(1000) ' Slow down only necessary for example
    If Err Then
      PerformReboot
      WScript.Quit
    End If
    oProgressBar.Tick numSeconds - i
Next

oProgressBar.Complete

PerformReboot

WScript.Quit()

Private Sub PerformReboot()
      Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true") 
      for each OpSys in OpSysSet 
             opsys.Win32ShutDown 2,0
      next
End Sub


'Begin IEProgressBar Class
Class IEProgressBar

Private oExplorer        ' Internet Explorer object
Private oDocument        ' IE Document object
Private iCounter        ' Counts # of ticks on progress bar
Private oWshShell        ' WshShell object
Public sTitle            ' Title of IE object
Public sHeader            ' Header comment of progress bar
Public sHeader2
Public sFooter            ' Trailing comment when bar complete
Public bSilent            ' Silent mode disables OK button at end of bar
Public iWidth            ' Width if IE dialog - Set before DisplayHeader
Public iHeight            ' Height of IE dialog - Set before DisplayHeader

Private Sub Class_Initialize
    iWidth = 400            ' default Width
    iHeight = 200            ' default Height
    sTitle = "Progress Bar"    ' default Title
    sHeader = "Starting"    ' default Header
    sFooter = "Done"        ' default Footer
    bSilent = False            ' default Silent mode
    Set oWshShell = CreateObject("Wscript.Shell")
    Set oExplorer = WScript.CreateObject _
     ("InternetExplorer.Application", "IE_")
    oExplorer.Navigate "about:blank" 
    oExplorer.ToolBar = False
    oExplorer.StatusBar = False
    oExplorer.Width = iWidth
    oExplorer.Height = iHeight
                
    Do While (oExplorer.Busy)    ' Wait untill IE loads
        Wscript.Sleep 100
    Loop
    
    iCounter = 0
End Sub

Private Sub Class_Terminate
    If IsObject( oDocument ) Then Set oDocument = Nothing
    If IsObject( oExplorer ) Then Set oExplorer = Nothing
    If IsObject( oWshShell ) Then Set oWshShell = Nothing
End Sub

Private Sub IEDoc(sFunc, sHTML)
    On Error Resume Next
    Select Case sFunc
        Case "Open"
            oDocument.Open
        Case "Close"
            oDocument.Close
        Case "Writeln"
            oDocument.Writeln(sHTML)
        Case "Write"
            oDocument.Write(sHTML)
        Case Else
    End Select
End Sub

Public Sub DisplayHeader 
    Dim sIETitle
    oExplorer.Width = iWidth 
    oExplorer.Height = iHeight 
    Set oDocument = oExplorer.Document 
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<script language=""VBScript"">") 
    Call IEDoc("Writeln","Sub Window_OnLoad()") 
    Call IEDoc("Writeln","theleft = (screen.availWidth - document.body.clientWidth) / 2") 
    Call IEDoc("Writeln","thetop = (screen.availHeight - document.body.clientHeight) / 2") 
    Call IEDoc("Writeln","window.moveTo theleft,thetop") 
    Call IEDoc("Writeln","End Sub") 
    Call IEDoc("Writeln","</script>") 
    Call IEDOc("Close",Null) 
 
    Call IEDoc("Open",Null)  
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>") 
    Call IEDoc("Writeln","<body bgcolor='white'>") 
    Call IEDoc("Writeln","<font color=black face=""Arial"">") 
    Call IEDoc("Writeln",sHeader & " " & sHeader2 & "<p>") 
    Call IEDoc("Writeln","</font>") 
    Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">") 
    
    Dim oReg
    Dim sIEBranding
    Dim oShell
    Set oShell = CreateObject("WScript.Shell")
    sIEBranding = oShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\Window Title")
    oExplorer.Visible = True
    sIETitle = "http:// - " & sTitle & " - " & sIEBranding
    'MsgBox "Looking for " & sIETitle
    Do Until oWshShell.AppActivate(sIETitle)        ' Wait till focus given 
        Wscript.Sleep 100
    Loop  
End Sub

Public Sub Tick(secondsRemaining)
      Dim j
        Call IEDOc("Close",Null)
        Call IEDoc("Open",Null) 
        Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
        Call IEDoc("Writeln","<body bgcolor='white'>")
        Call IEDoc("Writeln","<font color=black face=""Arial"">")
        Call IEDoc("Writeln","System will reboot in " & secondsRemaining & " seconds.  Please save your work... " & sHeader2 & "<p>")
      Call IEDoc("Writeln","</font>")
      Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">")

    iCounter = iCounter + 1
    for j = 1 to iCounter
      Call IEDoc("Write","n")
    Next

    If iCounter = 10 Then
      iCounter = 0
    End If
End Sub

Public Sub Complete
    Call IEDOc("Close",Null)
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
    Call IEDoc("Writeln","<body bgcolor='white'>")
    'Call IEDoc("Writeln","<font color=black face=""Arial"">")
    'Call IEDoc("Writeln",sHeader & "<p>")
    Call IEDoc("Writeln","<br><p><p>" & sFooter)
    Call IEDoc("Writeln","</font>")
    
    Call IEDoc("Writeln","<script language=""VBScript"">")
    Call IEDoc("Writeln","Public InputComplete")
    Call IEDoc("Writeln","Sub buttonOK_OnClick")
    Call IEDoc("Writeln","        InputComplete = 1 ' User input is ready")
    Call IEDoc("Writeln","End Sub")
    Call IEDoc("Writeln","</script>")
    
    Call IEDoc("Writeln","<form name=""ParameterForm"">")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","<input type=""button"" name=""ButtonOK"" value=""OK""><br>")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","</form>")
    Call IEDoc("Writeln","</body></html>")
    Call IEDoc("Close",Null)
        
    On Error Resume Next
    If Not bSilent Then
        Do ' Waiting for OK button
            Wscript.Sleep 100
        Loop While (oExplorer.document.script.InputComplete = 0)
    End If
    If Err Then
        Err.Clear()
        Wscript.quit()
    End If
    On Error Goto 0
    
    oExplorer.Quit 
End Sub

End Class 

Open in new window

0
 
RobSampsonCommented:
Can you run Regedit and navigate to that key? Does the value "Window Title" exist?  If not, try this code.

Regards,

Rob.
Dim oProgressBar
Dim sComputer
Dim oWMIService
Dim cServices
Dim oService
Dim numSeconds
Dim i

'Set the number of seconds before reboot
numSeconds = 20

Set oProgressBar = New IEProgressBar
oProgressBar.sTitle = "System Reboot"
oProgressBar.sHeader = "System will reboot in " & numSeconds & " seconds.  Please save your work..."
oProgressBar.sHeader2 = "Closing this window will result in an immediate reboot."
oProgressBar.sFooter = "Rebooting..."
oProgressBar.bSilent = True
oProgressBar.DisplayHeader

For i = 0 to numSeconds
    WScript.Sleep(1000) ' Slow down only necessary for example
    If Err Then
      PerformReboot
      WScript.Quit
    End If
    oProgressBar.Tick numSeconds - i
Next

oProgressBar.Complete

PerformReboot

WScript.Quit()

Private Sub PerformReboot()
      Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true") 
      for each OpSys in OpSysSet 
             opsys.Win32ShutDown 2,0
      next
End Sub


'Begin IEProgressBar Class
Class IEProgressBar

Private oExplorer        ' Internet Explorer object
Private oDocument        ' IE Document object
Private iCounter        ' Counts # of ticks on progress bar
Private oWshShell        ' WshShell object
Public sTitle            ' Title of IE object
Public sHeader            ' Header comment of progress bar
Public sHeader2
Public sFooter            ' Trailing comment when bar complete
Public bSilent            ' Silent mode disables OK button at end of bar
Public iWidth            ' Width if IE dialog - Set before DisplayHeader
Public iHeight            ' Height of IE dialog - Set before DisplayHeader

Private Sub Class_Initialize
    iWidth = 400            ' default Width
    iHeight = 200            ' default Height
    sTitle = "Progress Bar"    ' default Title
    sHeader = "Starting"    ' default Header
    sFooter = "Done"        ' default Footer
    bSilent = False            ' default Silent mode
    Set oWshShell = CreateObject("Wscript.Shell")
    Set oExplorer = WScript.CreateObject _
     ("InternetExplorer.Application", "IE_")
    oExplorer.Navigate "about:blank" 
    oExplorer.ToolBar = False
    oExplorer.StatusBar = False
    oExplorer.Width = iWidth
    oExplorer.Height = iHeight
                
    Do While (oExplorer.Busy)    ' Wait untill IE loads
        Wscript.Sleep 100
    Loop
    
    iCounter = 0
End Sub

Private Sub Class_Terminate
    If IsObject( oDocument ) Then Set oDocument = Nothing
    If IsObject( oExplorer ) Then Set oExplorer = Nothing
    If IsObject( oWshShell ) Then Set oWshShell = Nothing
End Sub

Private Sub IEDoc(sFunc, sHTML)
    On Error Resume Next
    Select Case sFunc
        Case "Open"
            oDocument.Open
        Case "Close"
            oDocument.Close
        Case "Writeln"
            oDocument.Writeln(sHTML)
        Case "Write"
            oDocument.Write(sHTML)
        Case Else
    End Select
End Sub

Public Sub DisplayHeader 
    Dim sIETitle
    oExplorer.Width = iWidth 
    oExplorer.Height = iHeight 
    Set oDocument = oExplorer.Document 
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<script language=""VBScript"">") 
    Call IEDoc("Writeln","Sub Window_OnLoad()") 
    Call IEDoc("Writeln","theleft = (screen.availWidth - document.body.clientWidth) / 2") 
    Call IEDoc("Writeln","thetop = (screen.availHeight - document.body.clientHeight) / 2") 
    Call IEDoc("Writeln","window.moveTo theleft,thetop") 
    Call IEDoc("Writeln","End Sub") 
    Call IEDoc("Writeln","</script>") 
    Call IEDOc("Close",Null) 
 
    Call IEDoc("Open",Null)  
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>") 
    Call IEDoc("Writeln","<body bgcolor='white'>") 
    Call IEDoc("Writeln","<font color=black face=""Arial"">") 
    Call IEDoc("Writeln",sHeader & " " & sHeader2 & "<p>") 
    Call IEDoc("Writeln","</font>") 
    Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">") 
    
    Dim oReg
    Dim sIEBranding
    Dim oShell
    Set oShell = CreateObject("WScript.Shell")
    sIEBranding = ""
    On Error Resume Next
    sIEBranding = oShell.RegRead("HKCU\Software\Microsoft\Internet Explorer\Main\Window Title")
    Err.Clear
   	On Error GoTo 0
    oExplorer.Visible = True
    sIETitle = "http:// - " & sTitle & " - " & sIEBranding
    'MsgBox "Looking for " & sIETitle
    Do Until oWshShell.AppActivate(sIETitle)        ' Wait till focus given 
        Wscript.Sleep 100
    Loop  
End Sub

Public Sub Tick(secondsRemaining)
      Dim j
        Call IEDOc("Close",Null)
        Call IEDoc("Open",Null) 
        Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
        Call IEDoc("Writeln","<body bgcolor='white'>")
        Call IEDoc("Writeln","<font color=black face=""Arial"">")
        Call IEDoc("Writeln","System will reboot in " & secondsRemaining & " seconds.  Please save your work... " & sHeader2 & "<p>")
      Call IEDoc("Writeln","</font>")
      Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">")

    iCounter = iCounter + 1
    for j = 1 to iCounter
      Call IEDoc("Write","n")
    Next

    If iCounter = 10 Then
      iCounter = 0
    End If
End Sub

Public Sub Complete
    Call IEDOc("Close",Null)
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
    Call IEDoc("Writeln","<body bgcolor='white'>")
    'Call IEDoc("Writeln","<font color=black face=""Arial"">")
    'Call IEDoc("Writeln",sHeader & "<p>")
    Call IEDoc("Writeln","<br><p><p>" & sFooter)
    Call IEDoc("Writeln","</font>")
    
    Call IEDoc("Writeln","<script language=""VBScript"">")
    Call IEDoc("Writeln","Public InputComplete")
    Call IEDoc("Writeln","Sub buttonOK_OnClick")
    Call IEDoc("Writeln","        InputComplete = 1 ' User input is ready")
    Call IEDoc("Writeln","End Sub")
    Call IEDoc("Writeln","</script>")
    
    Call IEDoc("Writeln","<form name=""ParameterForm"">")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","<input type=""button"" name=""ButtonOK"" value=""OK""><br>")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","</form>")
    Call IEDoc("Writeln","</body></html>")
    Call IEDoc("Close",Null)
        
    On Error Resume Next
    If Not bSilent Then
        Do ' Waiting for OK button
            Wscript.Sleep 100
        Loop While (oExplorer.document.script.InputComplete = 0)
    End If
    If Err Then
        Err.Clear()
        Wscript.quit()
    End If
    On Error Goto 0
    
    oExplorer.Quit 
End Sub

End Class

Open in new window

0
 
beckman55Author Commented:
No the only key that starts with Windows there is  "Window Placement"  I'll try the code above now.
0
 
beckman55Author Commented:
That fixed the error and the window comes up.....but doesn't shutdown even if I close the window.  I don't see any red boxes like you mentioned.
window.bmp
0
 
RobSampsonCommented:
Hmm, I can see the title is a bit different. Try this.

I've added this line:
    sIETitle = "http:/// - " & sTitle & " - Windows Internet Explorer"

so see if that works. You may need to remove one of the forward slashes after http: but see how you go.

Regards,

Rob.
Dim oProgressBar
Dim sComputer
Dim oWMIService
Dim cServices
Dim oService
Dim numSeconds
Dim i

'Set the number of seconds before reboot
numSeconds = 20

Set oProgressBar = New IEProgressBar
oProgressBar.sTitle = "System Reboot"
oProgressBar.sHeader = "System will reboot in " & numSeconds & " seconds.  Please save your work..."
oProgressBar.sHeader2 = "Closing this window will result in an immediate reboot."
oProgressBar.sFooter = "Rebooting..."
oProgressBar.bSilent = True
oProgressBar.DisplayHeader

For i = 0 to numSeconds
    WScript.Sleep(1000) ' Slow down only necessary for example
    If Err Then
      PerformReboot
      WScript.Quit
    End If
    oProgressBar.Tick numSeconds - i
Next

oProgressBar.Complete

PerformReboot

WScript.Quit()

Private Sub PerformReboot()
      Set OpSysSet = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true") 
      for each OpSys in OpSysSet 
             opsys.Win32ShutDown 2,0
      next
End Sub


'Begin IEProgressBar Class
Class IEProgressBar

Private oExplorer        ' Internet Explorer object
Private oDocument        ' IE Document object
Private iCounter        ' Counts # of ticks on progress bar
Private oWshShell        ' WshShell object
Public sTitle            ' Title of IE object
Public sHeader            ' Header comment of progress bar
Public sHeader2
Public sFooter            ' Trailing comment when bar complete
Public bSilent            ' Silent mode disables OK button at end of bar
Public iWidth            ' Width if IE dialog - Set before DisplayHeader
Public iHeight            ' Height of IE dialog - Set before DisplayHeader

Private Sub Class_Initialize
    iWidth = 400            ' default Width
    iHeight = 200            ' default Height
    sTitle = "Progress Bar"    ' default Title
    sHeader = "Starting"    ' default Header
    sFooter = "Done"        ' default Footer
    bSilent = False            ' default Silent mode
    Set oWshShell = CreateObject("Wscript.Shell")
    Set oExplorer = WScript.CreateObject _
     ("InternetExplorer.Application", "IE_")
    oExplorer.Navigate "about:blank" 
    oExplorer.ToolBar = False
    oExplorer.StatusBar = False
    oExplorer.Width = iWidth
    oExplorer.Height = iHeight
                
    Do While (oExplorer.Busy)    ' Wait untill IE loads
        Wscript.Sleep 100
    Loop
    
    iCounter = 0
End Sub

Private Sub Class_Terminate
    If IsObject( oDocument ) Then Set oDocument = Nothing
    If IsObject( oExplorer ) Then Set oExplorer = Nothing
    If IsObject( oWshShell ) Then Set oWshShell = Nothing
End Sub

Private Sub IEDoc(sFunc, sHTML)
    On Error Resume Next
    Select Case sFunc
        Case "Open"
            oDocument.Open
        Case "Close"
            oDocument.Close
        Case "Writeln"
            oDocument.Writeln(sHTML)
        Case "Write"
            oDocument.Write(sHTML)
        Case Else
    End Select
End Sub

Public Sub DisplayHeader 
    Dim sIETitle
    oExplorer.Width = iWidth 
    oExplorer.Height = iHeight 
    Set oDocument = oExplorer.Document 
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<script language=""VBScript"">") 
    Call IEDoc("Writeln","Sub Window_OnLoad()") 
    Call IEDoc("Writeln","theleft = (screen.availWidth - document.body.clientWidth) / 2") 
    Call IEDoc("Writeln","thetop = (screen.availHeight - document.body.clientHeight) / 2") 
    Call IEDoc("Writeln","window.moveTo theleft,thetop") 
    Call IEDoc("Writeln","End Sub") 
    Call IEDoc("Writeln","</script>") 
    Call IEDOc("Close",Null) 
 
    Call IEDoc("Open",Null)  
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>") 
    Call IEDoc("Writeln","<body bgcolor='white'>") 
    Call IEDoc("Writeln","<font color=black face=""Arial"">") 
    Call IEDoc("Writeln",sHeader & " " & sHeader2 & "<p>") 
    Call IEDoc("Writeln","</font>") 
    Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">") 
    
    oExplorer.Visible = True
    sIETitle = "http:/// - " & sTitle & " - Windows Internet Explorer"
    'MsgBox "Looking for " & sIETitle
    Do Until oWshShell.AppActivate(sIETitle)        ' Wait till focus given 
        Wscript.Sleep 100
    Loop  
End Sub

Public Sub Tick(secondsRemaining)
      Dim j
        Call IEDOc("Close",Null)
        Call IEDoc("Open",Null) 
        Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
        Call IEDoc("Writeln","<body bgcolor='white'>")
        Call IEDoc("Writeln","<font color=black face=""Arial"">")
        Call IEDoc("Writeln","System will reboot in " & secondsRemaining & " seconds.  Please save your work... " & sHeader2 & "<p>")
      Call IEDoc("Writeln","</font>")
      Call IEDoc("Writeln","<font size=6 color=red face=""wingdings"">")

    iCounter = iCounter + 1
    for j = 1 to iCounter
      Call IEDoc("Write","n")
    Next

    If iCounter = 10 Then
      iCounter = 0
    End If
End Sub

Public Sub Complete
    Call IEDOc("Close",Null)
    Call IEDoc("Open",Null) 
    Call IEDoc("Writeln","<html><head><title>" & sTitle & "</title></head>")
    Call IEDoc("Writeln","<body bgcolor='white'>")
    'Call IEDoc("Writeln","<font color=black face=""Arial"">")
    'Call IEDoc("Writeln",sHeader & "<p>")
    Call IEDoc("Writeln","<br><p><p>" & sFooter)
    Call IEDoc("Writeln","</font>")
    
    Call IEDoc("Writeln","<script language=""VBScript"">")
    Call IEDoc("Writeln","Public InputComplete")
    Call IEDoc("Writeln","Sub buttonOK_OnClick")
    Call IEDoc("Writeln","        InputComplete = 1 ' User input is ready")
    Call IEDoc("Writeln","End Sub")
    Call IEDoc("Writeln","</script>")
    
    Call IEDoc("Writeln","<form name=""ParameterForm"">")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","<input type=""button"" name=""ButtonOK"" value=""OK""><br>")
    Call IEDoc("Writeln","<P>")
    Call IEDoc("Writeln","</form>")
    Call IEDoc("Writeln","</body></html>")
    Call IEDoc("Close",Null)
        
    On Error Resume Next
    If Not bSilent Then
        Do ' Waiting for OK button
            Wscript.Sleep 100
        Loop While (oExplorer.document.script.InputComplete = 0)
    End If
    If Err Then
        Err.Clear()
        Wscript.quit()
    End If
    On Error Goto 0
    
    oExplorer.Quit 
End Sub

End Class

Open in new window

0
 
beckman55Author Commented:
That worked perfectly.  I saw the red boxes countdown then my system rebooted.  Thanks again
0
 
RobSampsonCommented:
Excellent. Thanks for the grade.

Regards,

Rob.
0
 
jschiavoneCommented:
I would like to see if the script can shutdown a PC instead of reboot and also I want to give the users a cancel buttom.

Thanks
Jamie
0
 
RobSampsonCommented:
Hi, for a forced shutdown, simply change this line:
             opsys.Win32ShutDown 2,0

to this
             opsys.Win32ShutDown 5,0


For a cancel, in this section:
    If Err Then
      PerformReboot
      WScript.Quit
    End If

if you remove the PerformReboot from there, then you will be able to close the window manually and it should not reboot / shutdown.

Regards,

Rob.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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