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

Pop Up Box to Restart a Computer

I did a search for this particular question and was able to locate an answer for half of the question.  The code below written by Mark D. MacLachlan works great on Windows XP.  

However, for Windows 7, when you click "No", the pop up does not come up again.  Please help.  Thank you.

'==========================================================================
'
' NAME: RebootWS30MinuteNag.vbs
'
' AUTHOR:  Mark D. MacLachlan, The Spider's Parlor
' COPYRIGHT: (c) 2010 All Rights Reserved
' DATE  : 3/12/2010
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.

'
' COMMENT: Reboots a workstation.
'          
'
'==========================================================================

On Error Resume Next
mName = "."
Set WSHShell = CreateObject("Wscript.Shell")
PromptText = "A security patch was installed on your computer. " & vbCrLf & _
"Your computer needs to restart to take effect. " & vbCrLf & _
"Please save all your datas before restarting. " & vbCrLf & _
"OK to restart now?"

If Msgbox(PromptText, vbYesNo, "Machine Reboot Needed") = vbYes then
        WSHShell.RUN("CMD.EXE /C shutdown -r -t 00")
Else
        NextNag = DateAdd("N", 30, Time)
        NextNag = Right("0" & Hour(NextNag),2)& ":" & Right(Minute(NextNag),2)
        WSHShell.RUN("CMD.EXE /C AT " & NextNag & " /interactive " & Chr(34) & WScript.ScriptFullName & Chr(34))
        MsgBox "You will be reminded to restart again in 30 minutes."
End If
-----------------------------------------------
0
masaiming
Asked:
masaiming
  • 4
  • 3
1 Solution
 
RobSampsonCommented:
As far as I'm aware, to use AT on Windows 7 to add a scheduled task, you need to be an Administrator.  You should get away with replacing this:
If Msgbox(PromptText, vbYesNo, "Machine Reboot Needed") = vbYes then
        WSHShell.RUN("CMD.EXE /C shutdown -r -t 00")
Else
        NextNag = DateAdd("N", 30, Time)
        NextNag = Right("0" & Hour(NextNag),2)& ":" & Right(Minute(NextNag),2)
        WSHShell.RUN("CMD.EXE /C AT " & NextNag & " /interactive " & Chr(34) & WScript.ScriptFullName & Chr(34))
        MsgBox "You will be reminded to restart again in 30 minutes."
End If

Open in new window


with this:
If Msgbox(PromptText, vbYesNo, "Machine Reboot Needed") = vbYes then
        WSHShell.RUN("CMD.EXE /C shutdown -r -t 00")
Else
        ' Have the script pause for 30 minutes
        WScript.Sleep 1800000
        MsgBox "You will be reminded to restart again in 30 minutes."
End If

Open in new window


Regards,

Rob.
0
 
RobSampsonCommented:
Sorry....it actually needs a loop too.

Regards,

Rob.
On Error Resume Next
mName = "."
Set WSHShell = CreateObject("Wscript.Shell")
PromptText = "A security patch was installed on your computer. " & vbCrLf & _
"Your computer needs to restart to take effect. " & vbCrLf & _
"Please save all your datas before restarting. " & vbCrLf & _
"OK to restart now?"

wait = True
While wait = True
	If Msgbox(PromptText, vbYesNo, "Machine Reboot Needed") = vbYes then
		WSHShell.RUN("CMD.EXE /C shutdown -r -t 00")
		wait = False
	Else
		WScript.Sleep 1800000
		MsgBox "You will be reminded to restart again in 30 minutes."
	End If
Wend

Open in new window

0
 
masaimingAuthor Commented:
Thanks.  That worked great.  I have another question that might be a pain.  I can close off this question and open another one.  Would it be possible to do a time out if the user does not respond within a certain time to the original prompt or anytime after they click "no"?  Thank you again.  
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
RobSampsonCommented:
Hi, thanks for the grade.

To have a timeout on the Machine Reboot Needed prompt, you can use the
WSHShell.Popup method instead:
http://msdn.microsoft.com/en-us/library/x83z1d9f(v=vs.85).aspx

so this line:
      If Msgbox(PromptText, vbYesNo, "Machine Reboot Needed") = vbYes then

could be
                intResponse = WSHShell.Popup(PromptText, 20, "Machine Reboot Needed", 4)
      If intResponse = 6 Or intResponse = -1 Then

That would time out after 20 seconds.

Regards,

Rob.
0
 
masaimingAuthor Commented:
This script is exactly what I wanted.  Is there a way to give you extra points?  Well done RobSampson.  Now, I need to script like this.  Thank you again.  
0
 
masaimingAuthor Commented:
One last thing.  How do I change the score from 9.2 to a 10.  I wanted to give a 10 but it gave a 9.2 by itself.  
0
 
RobSampsonCommented:
Don't worry about the points, they don't account for much.

The scoring is generated automatically based on an algorithm that takes into account the number of posts, amount of experts involved, and the input of the author.  It is quite rare to obtain a 10 given those factors.

Regards,

Rob.
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.

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