Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

shutdown script

Posted on 2009-07-03
5
Medium Priority
?
875 Views
Last Modified: 2012-05-07
i need shutdown vbscript with msgbox " your computer will shutdown in x min Press Cancel to abort " 
if no one press cancel the shutdown command is going to continue. i have tried to write a script i need your help !!

TimeOut = 1 '(in minutes) how to use ?
or is there another way ??

dim objShell
Set WshShell = CreateObject("WScript.Shell") 
userschoice = Msgbox("The Computer is shuting down now", VBOKCancel + vbExclamation,"Caution")
 
If vbOK Then
        objShell.Run "shutdown.exe -s -t 30"
else
        Msgbox "Shutdown abortet"
End if

Open in new window

0
Comment
Question by:lovemask
[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
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
ou_dober earned 2000 total points
ID: 24773533
Hope this helps.
' Shutdown.vbs
' Example VBScript to shutdown computers w/ user input
' Author Lance Dobbs
' Version 1.1 - July 2009
' --------------------------------------
Dim objShell, strComputer, strInput
Dim strShutdown
 
' This parameter is for when the user clicks on the yes box.(adjust -t as needed - default 0 min.)
strShutdown1 = "shutdown -s -t 0 -f -m \\" & strComputer
' This parameter is for when the user clicks on the no box. (adjust -t as needed - default 5 min.)
strShutdown2 = "shutdown -s -t 300 -f -m \\" & strComputer
' This parameter is for when the user does nothing. (adjust -t as needed - default 0 min.)
' If this is not needed, REM out the line with "	objShell.Run strShutdown3"
strShutdown3 = "shutdown -s -t 0 -f -m \\" & strComputer
 
Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32
 
Set objShell = CreateObject("Wscript.Shell")
 
intReturn = objShell.Popup("Your computer needs to be shutdown. Do you wish to proceed right now?", _
    30, "***** SHUTDOWN REQUIRED *****", wshYesNoDialog + wshQuestionMark)
 
If intReturn = wshYes Then
   	Wscript.Echo "You clicked the Yes to shutdown your computer now."
	objShell.Run strShutdown1
ElseIf intReturn = wshNo Then
    	Wscript.Echo "You clicked the No button. Your computer will shutdown in 5 minutes. Please close all applications."
	objShell.Run strShutdown2
Else
    	Wscript.Echo "The popup timed out. Computer will shutdown now."
	objShell.Run strShutdown3
End If

Open in new window

0
 
LVL 6

Expert Comment

by:ou_dober
ID: 24773581
BTW ~ Adjust line 25 where 30 is the seconds it will wait before acting on its own without user intervention.
0
 

Author Comment

by:lovemask
ID: 24773585
thank you it seems working ... im testing it now
0
 
LVL 6

Expert Comment

by:ou_dober
ID: 24773588
Here's the one for rebooting
Set for 10 sec on no user intervention.
' Reboot.vbs
' Example VBScript to Reboot computers w/ user input
' Author Lance Dobbs
' Version 1.1 - July 2009
' --------------------------------------
Dim objShell, strComputer, strInput
Dim strReboot
 
' This parameter is for when the user clicks on the yes box.(adjust -t as needed - default 0 min.)
strReboot1 = "Shutdown -r -t 0 -f -m \\" & strComputer
' This parameter is for when the user clicks on the no box. (adjust -t as needed - default 5 min.)
strReboot2 = "Shutdown -r -t 300 -f -m \\" & strComputer
' This parameter is for when the user does nothing. (adjust -t as needed - default 0 min.)
' If this is not needed, REM out the line with "	objShell.Run strReboot3"
strReboot3 = "Shutdown -r -t 0 -f -m \\" & strComputer
 
Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32
 
Set objShell = CreateObject("Wscript.Shell")
 
intReturn = objShell.Popup("Your computer needs to be rebooted. Do you wish to proceed right now?", _
    10, "***** Reboot REQUIRED *****", wshYesNoDialog + wshQuestionMark)
 
If intReturn = wshYes Then
   	Wscript.Echo "You clicked the Yes to Reboot your computer now."
	objShell.Run strReboot1
ElseIf intReturn = wshNo Then
    	Wscript.Echo "You clicked the No button. Your computer will Reboot in 5 minutes. Please close all applications."
	objShell.Run strReboot2
Else
    	Wscript.Echo "The popup timed out. Computer will Reboot now."
	objShell.Run strReboot3
End If

Open in new window

0
 

Author Closing Comment

by:lovemask
ID: 31599618
thank you i did some modification that meet my requirements
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

610 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