masaiming
asked on
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.Shel l")
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
-------------------------- ---------- ---------- -
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.Shel
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
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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,
If intResponse = 6 Or intResponse = -1 Then
That would time out after 20 seconds.
Regards,
Rob.
ASKER
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.
ASKER
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.
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.
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.
Open in new window
with this:
Open in new window
Regards,
Rob.