VBSCRIPT: HOW DO I ADD A COUNTDOWN TO A SYSTEM REBOOT

I have a script that will force reboot a system, but I thought I would be fancy and add an echo, count down, can anyone help. Wanting to run the script and right before the reboot.....10 "mississippi', 9 mississippi, you get the idea?


Option Explicit

dim objShell, oEnv

Set objShell = CreateObject("WScript.Shell")
set oEnv = objShell.Environment("PROCESS")

'*****Note Do not use this as a permanent system environment variable because it will disable all Zone Checking.*****

'Disables "Open File - Security Warning".
oEnv("SEE_MASK_NOZONECHECKS") = 1

objShell.Run "C:\windows\system32\shutdown.exe -r -f -c " & """Reboot for desktop maintenance, other than 2AM reboot.""", , True

'Enables "Open File - Security Warning".
oEnv.Remove("SEE_MASK_NOZONECHECKS")

Wscript.Quit

'End of script.
rrangel8Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike ThomasConsultantCommented:
Add "-t AndANumber" (the number being in seconds

so add "-t 60" on to what you have for a 60 second timer.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike ThomasConsultantCommented:
Or run the script using a scheduled task it control panel if my other suggestion is not suitable.


0
sr75Commented:
Its not the best solution but I have attached a countdown timer for you.

On Error Resume Next

DIM intSeconds

intSeconds = 30

func_Countdown(intSeconds)

set intSeconds = Nothing

Function func_Countdown(intTimer)

        DIM WShell
        DIM strTitle
        DIM i
        DIM Cnt
        DIM strResult   

	Set WSHell = WScript.CreateObject("WScript.Shell")

	strTitle = intTimer & " Second Coundown"

	For i = 0 to intTimer
		Cnt = intTimer - i
		strResult = WShell.Popup(Cnt & " seconds left or press OK to skip countdown",1,strTitle,vbOkOnly)
		If strResult = 1 then
			Exit For
		End If
	Next 
	
	wscript.echo "All Done"

        set WShell = Nothing
        set strTitle = Nothing
        set i = Nothing
        set Cnt = Nothing
        set strResult = Nothing	

End Function 

Open in new window

0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

sr75Commented:
Sorry had a brain fart and this one is actually cleaner.  I got rid of the i counter because it isn't really needed.

On Error Resume Next

DIM intSeconds

intSeconds = 30

func_Countdown(intSeconds)

set intSeconds = Nothing

Function func_Countdown(intTimer)

        DIM WShell
        DIM strTitle
        DIM Cnt
        DIM strResult   

	Set WSHell = WScript.CreateObject("WScript.Shell")

	strTitle = intTimer & " Second Coundown"

	For Cnt = intTimer to 1 Step -1
		strResult = WShell.Popup(Cnt & " seconds left or press OK to skip countdown",1,strTitle,vbOkOnly)
		If strResult = 1 then
			Exit For
		End If
	Next 
	
	wscript.echo "All Done"

        set WShell = Nothing
        set strTitle = Nothing
        set Cnt = Nothing
        set strResult = Nothing	

End Function

Open in new window

0
sr75Commented:
MojoTech is right.  That is much better then what I put

Per his advice, you should change this line:

objShell.Run "C:\windows\system32\shutdown.exe -r -f -c " & """Reboot for desktop maintenance, other than 2AM reboot.""", , True


to this one instead:

objShell.Run "C:\windows\system32\shutdown.exe -r -f -t 60 -c " & """Reboot for desktop maintenance, other than 2AM reboot.""", , True
0
rrangel8Author Commented:
guys....I am glad that I signed up to EE. All of your inputs gave me something to think about and learn more about vbscripting. I consider myself a newbie to vb and hope to be as resourceful for you guys soon.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.