Solved

VB script choices

Posted on 2009-07-09
16
855 Views
Last Modified: 2012-08-13
I have two scripts I need to merge.

I have a script that pops up an informational window and waits X number of seconds, and then another that auto pops up and waits Y number of seconds, and then goes away and then a shutdown command is issued via Altiris.  

The second script wants to approach this a bit differently, by asking if the PC should be auto turned off, or not.  

How can I use the second script but have it essentially delay forever if they choose not to shut down, and to close/finish in 10 minutes if they DO choose to shutdown?
First Script:
 
dim naptime, naptime2, objDOS
naptime = 30
naptime2 = 20
set objDOS = CreateObject ("WScript.Shell")
objDOS.Popup "CONSERVATION IS IMPORTANT!" & vbcrlf & "" & vbcrlf & "IN AN EFFORT TO SAVE ENERGY WE ARE SHUTTING DOWN YOUR PC FOR THE NIGHT." & vbcrlf & "" & vbcrlf & " *** YOU HAVE 10 MINUTES BEFORE SHUT DOWN. PLEASE SAVE YOUR WORK NOW! ***" & vbcrlf & "" & vbcrlf & "IF YOU NEED TO USE YOUR PC AFTER IT HAS SHUT DOWN, YOU CAN POWER IT BACK ON AND CONTINUE WORKING." & vbcrlf & "" & vbcrlf & "IF YOUR PC IS NOT ON IN THE MORNING, POWER IT ON MANUALLY THEN." & vbcrlf & "" & vbcrlf & "(ATTENTION: Clicking OK now will shutdown your PC in FIVE minutes!)", naptime , "Information Technology Services is GOING GREEN", 0
objDOS.Popup "YOU HAVE 5 MINUTES BEFORE SHUTDOWN!" & vbcrlf & "" & vbcrlf & "ANY UNSAVED WORK MAY BE LOST!" & vbcrlf & "" & vbcrlf & "(Clicking OK now will shutdown your PC instantly!)" & vbcrlf & "" & vbcrlf & "PLEASE TURN YOUR MONITOR OFF NOW! HELP US CONSERVE ENERGY!", naptime2 , "***PC SHUTDOWN IN 5 MINUTES!***", 0
 
---------------------------------
 
Second Script:
 
Option Explicit
 
MsgBox "CONSERVATION IS IMPORTANT!" & vbcrlf & "" & vbcrlf & "IN AN EFFORT TO SAVE ENERGY WE WOULD LIKE TO SHUT DOWN YOUR PC FOR THE NIGHT." & vbcrlf & "" & vbcrlf & "" & vbcrlf & "                                  *** IF YOU CHOOSE TO SHUT DOWN," & vbcrlf & "              YOU HAVE 10 MINUTES TO SAVE YOUR FILES AND CLOSE PROGRAMS. ***" & vbcrlf & "" & vbcrlf & "" & vbcrlf & "IF YOU NEED CHOOSE NOT TO SHUT DOWN NOW, PLEASE POWER YOUR PC OFF WHEN FINISHED." & vbcrlf & "" & vbcrlf & "IF YOUR PC IS NOT ON IN THE MORNING, POWER IT ON MANUALLY." & vbcrlf & "" & vbcrlf & "(CLICK OK NOW TO CHOOSE TO SHUTDOWN OR CANCEL THIS PROGRAM.)", vbInformation, "Information Technology Services is GOING GREEN"
 
If MsgBox("Click YES to shutdown in 10 minutes, click NO to turn computer off manually.", vbQuestion + vbYesNo, "SHUTDOWN?") = vbYes Then
	MsgBox "Computer will shut down in 10 minutes!", vbInformation
Else
	MsgBox "Computer will NOT auto shut down." & vbcrlf & "Please turn off your PC when finished.", vbInformation
End If

Open in new window

0
Comment
Question by:ITS-DCO
[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
  • 9
  • 7
16 Comments
 
LVL 2

Expert Comment

by:whomJesusloves
ID: 24816161
Here's a related post:

http://www.experts-exchange.com/Microsoft/Applications/Q_24542687.html



Option Explicit
 
MsgBox "CONSERVATION IS IMPORTANT!" & vbcrlf & "" & vbcrlf & "IN AN 
 
EFFORT TO SAVE ENERGY WE WOULD LIKE TO SHUT DOWN YOUR PC FOR THE 
 
NIGHT." & vbcrlf & "" & vbcrlf & "" & vbcrlf & "                    
 
              *** IF YOU CHOOSE TO SHUT DOWN," & vbcrlf & "         
 
     YOU HAVE 10 MINUTES TO SAVE YOUR FILES AND CLOSE PROGRAMS. 
 
***" & vbcrlf & "" & vbcrlf & "" & vbcrlf & "IF YOU NEED CHOOSE NOT 
 
TO SHUT DOWN NOW, PLEASE POWER YOUR PC OFF WHEN FINISHED." & vbcrlf 
 
& "" & vbcrlf & "IF YOUR PC IS NOT ON IN THE MORNING, POWER IT ON 
 
MANUALLY." & vbcrlf & "" & vbcrlf & "(CLICK OK NOW TO CHOOSE TO 
 
SHUTDOWN OR CANCEL THIS PROGRAM.)", vbInformation, "Information 
 
Technology Services is GOING GREEN"
 
If MsgBox("Click YES to shutdown in 10 minutes, click NO to turn 
 
computer off manually.", vbQuestion + vbYesNo, "SHUTDOWN?") = vbYes 
 
Then
        MsgBox "Computer will shut down in 10 minutes!", 
 
vbInformation
	start_timer()
Else
        MsgBox "Computer will NOT auto shut down." & vbcrlf & 
 
"Please turn off your PC when finished.", vbInformation
End If
 
Function start_timer()
	Set objShell = CreateObject("Wscript.Shell")
	objShell.Run "shutdown -s -t 600 -f"
End Funciton

Open in new window

0
 
LVL 2

Expert Comment

by:whomJesusloves
ID: 24816169
Sorry - it goofed up the text when pasting from Notepad
0
 

Author Comment

by:ITS-DCO
ID: 24816228
I will test! Thanks!
0
Independent Software Vendors: 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!

 

Author Comment

by:ITS-DCO
ID: 24824052
That sort of helps, but I was hoping for something I could customize to continue to remind someone to shutdown.

I've tried modifying the script in the link to call a file that would wait a set period and then run the entire VB script again, but it shows the initial msgbox and then does nothing after that.  Any thoughts?
0
 

Author Comment

by:ITS-DCO
ID: 24824352
Attached is my current code... I'm also wondering if I can hide the delay message that shutdown.exe creates.
Dim objShell, strComputer, strInput
Dim strShutdown
 
' This parameter is for when the user clicks on the yes box.(adjust -t as needed - default 5 min.)
strShutdown1 = "\\dss\apps\shutdown\shutdown.exe -u -t 300 -f >nul" & strComputer
' This parameter is for when the user clicks on the no box. 
' strShutdown2 = "cscript \\dss\apps\shutdown\msg.vbs //NoLogo >nul" & 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 = "\\dss\apps\shutdown\shutdown.exe -u -t 0 -f" & strComputer
 
Const wshYes = 6
Const wshNo = 7
Const wshYesNoDialog = 4
Const wshQuestionMark = 32
 
Set objShell = CreateObject("Wscript.Shell")
 
intReturn = objShell.Popup("CONSERVATION IS IMPORTANT!" & vbcrlf & "" & vbcrlf & "IN AN EFFORT TO SAVE ENERGY WE WANT TO SHUT DOWN YOUR PC FOR THE NIGHT." & vbcrlf & "" & vbcrlf & " *** CLICK YES AND YOUR COMPUTER WILL SHUT DOWN IN 5 MINUTES. PLEASE SAVE YOUR WORK NOW! ***" & vbcrlf & "" & vbcrlf & "CLICK NO TO CANCEL. DO NOTHING AND YOUR PC WILL SHUT DOWN AUTOMATICALLY." & vbcrlf & "" & vbcrlf & "IF YOUR PC IS NOT ON IN THE MORNING, POWER IT ON MANUALLY.", vbInformation, "Information Technology Services is GOING GREEN", wshYesNoDialog + wshQuestionMark)
 
If intReturn = wshYes Then
        Wscript.Echo "You clicked the Yes button.  Your computer will shutdown in 5 minutes. Please close all applications."
        objShell.Run strShutdown1
ElseIf intReturn = wshNo Then
        Wscript.Echo "CONSERVATION IS IMPORTANT!  WHEN YOU ARE FINISHED USING YOUR PC FOR THE NIGHT PLEASE TURN IT AND THE MONITOR OFF."
Else
        objShell.Run strShutdown3
End If

Open in new window

0
 
LVL 2

Expert Comment

by:whomJesusloves
ID: 24825048
i wrote this in answer to the post before your latest:


If no is clicked, it will wait 10 mins, and run the whole script again.
If yes is clicked, it will shutdown in 10 mins.

To avoid the shutdown prompt, you can use:
                Wscript.Sleep(600*1000)
                objShell.Run "shutdown -s -t 0 -f"


instead of :
            Set objShell = CreateObject("WScript.Shell")
            objShell.Run "shutdown -s -t 600 -f"
Option Explicit
Dim objShell, mins
 
main()
 
Function main()
 	MsgBox "CONSERVATION IS IMPORTANT!" & vbcrlf & "" & vbcrlf &_
		"IN AN EFFORT TO SAVE ENERGY WE WOULD LIKE TO SHUT DOWN YOUR PC FOR THE NIGHT." &_
		vbcrlf & "" & vbcrlf & "" & vbcrlf & "                                  *** IF YOU CHOOSE TO SHUT DOWN," &_
		vbcrlf & "              YOU HAVE 10 MINUTES TO SAVE YOUR FILES AND CLOSE PROGRAMS. ***" &_
		vbcrlf & "" & vbcrlf & "" & vbcrlf &_
		"IF YOU NEED CHOOSE NOT TO SHUT DOWN NOW, PLEASE POWER YOUR PC OFF WHEN FINISHED." & vbcrlf &_
		"" & vbcrlf & "IF YOUR PC IS NOT ON IN THE MORNING, POWER IT ON MANUALLY." & vbcrlf & "" & vbcrlf &_
		"(CLICK OK NOW TO CHOOSE TO SHUTDOWN OR CANCEL THIS PROGRAM.)",_
		vbInformation, "Information Technology Services is GOING GREEN"
	 
 
	If MsgBox("Click YES to shutdown in 10 minutes, click NO to turn computer off manually.",_
			vbQuestion + vbYesNo,"SHUTDOWN?") = vbYes Then
		MsgBox "Computer will shut down in 10 minutes!", vbInformation
		
		Set objShell = CreateObject("WScript.Shell")
		objShell.Run "shutdown -s -t 600 -f"
	Else
		MsgBox "Computer will NOT auto shut down." & vbcrlf &_
			"Please turn off your PC when finished.", vbInformation
		WScript.Sleep(6*1000) ''That's 600 seconds * 1000(it's measured in milliseconds).
		main()  ''This reruns the main() function.
	End If
End Function

Open in new window

0
 

Author Comment

by:ITS-DCO
ID: 24825118
Thanks! I will try it!
0
 
LVL 2

Expert Comment

by:whomJesusloves
ID: 24825183
correction on my previous post:
keep the 'CreateObject' line in there, or it will throw an error.

     Set objShell = CreateObject("WScript.Shell")
     Wscript.Sleep(600*1000)
     objShell.Run "shutdown -s -t 0 -f"
0
 

Author Comment

by:ITS-DCO
ID: 24825335
That seems to work.  What if no one responds at ALL to the first pop-up?
0
 

Author Comment

by:ITS-DCO
ID: 24825663
By this, I mean, can I have it shutdown the PC if no one touches the initial popup in x minutes?
0
 
LVL 2

Expert Comment

by:whomJesusloves
ID: 24825752
It'll sit there until they do.  If you wanted, you could start a 30 min shutdown (showing the countdown screen along with the popup)  and cancel it when/if they respond to the popup.
0
 

Author Comment

by:ITS-DCO
ID: 24825796
I'd rather not show any countdown. Just have the vbs autoexecute a shutdown if not touched.  Is that possible?
0
 
LVL 2

Accepted Solution

by:
whomJesusloves earned 500 total points
ID: 24826542
Using the Wscript.popup method, you can time a messagebox.

See if this works for you.
Option Explicit
Dim objShell, mins, strMsg, intReturn
 
main()
 
Function main()
	Const wshYes = 6
	Const wshNo = 7
	Const vbOKOnly = 0
	Const wshYesNoDialog = 4
	Const wshQuestionMark = 32 
	
	Set objShell = CreateObject("Wscript.Shell")
 
	strMsg = "CONSERVATION IS IMPORTANT!" & vbcrlf & "" & vbcrlf &_
			"IN AN EFFORT TO SAVE ENERGY WE WOULD LIKE TO SHUT DOWN YOUR PC FOR THE NIGHT." &_
			vbcrlf & "" & vbcrlf & "" & vbcrlf & "                                  *** IF YOU CHOOSE TO SHUT DOWN," &_
			vbcrlf & "              YOU HAVE 10 MINUTES TO SAVE YOUR FILES AND CLOSE PROGRAMS. ***" &_
			vbcrlf & "" & vbcrlf & "" & vbcrlf &_
			"IF YOU NEED CHOOSE NOT TO SHUT DOWN NOW, PLEASE POWER YOUR PC OFF WHEN FINISHED." & vbcrlf &_
			"" & vbcrlf & "IF YOUR PC IS NOT ON IN THE MORNING, POWER IT ON MANUALLY." & vbcrlf & "" & vbcrlf &_
			"(CLICK OK NOW TO CHOOSE TO SHUTDOWN OR CANCEL THIS PROGRAM.)"
	
	intReturn = objShell.Popup(strMsg, 20, "Information Technology Services is GOING GREEN", vbOKOnly)
	
	If intReturn = -1 then
		shutdown()
	Else
		intReturn = objShell.Popup("Click YES to shutdown in 10 minutes, click NO to turn computer off manually.", 30, "SHUTDOWN?", wshQuestionMark + vbYesNo)
 
		If intReturn <> wshNo Then
			shutdown()
		Else
				MsgBox "Computer will NOT auto shut down." & vbcrlf &_
						"Please turn off your PC when finished."
				WScript.Sleep(600*1000) ''That's 600 seconds * 1000(it's measured in milliseconds).
				main()  ''This reruns the main() function.
		End If
	End If
End Function
 
 
Function Shutdown()
	intReturn = objShell.Popup("Computer will shut down in 10 minutes!", 20, "Information Technology Services is GOING GREEN", vbOKOnly)
	Set objShell = CreateObject("WScript.Shell")
	Wscript.Sleep(600*1000)
	objShell.Run "shutdown -s -t 0 -f"
End Function

Open in new window

0
 
LVL 2

Expert Comment

by:whomJesusloves
ID: 24826576
0
 

Author Comment

by:ITS-DCO
ID: 24872521
Thanks for your help!  This is working well (except that when you say NO the first time, it waits 10 mins and asks again, which is great, and no matter what you say then reboots you in 10 mins).  I will play with the settings.

Thanks!
0
 

Author Comment

by:ITS-DCO
ID: 24872599
Correction. It's working perfectly.  I love it!
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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