VB Script reboot with button to abort

I am looking for a VB Script to reboot the computer with a button to abort it.

I am using batch script shutdown -r -t xx but if this can integrate with VB function "MsgBox" that would be nice.

Thanks!
LVL 21
MazdajaiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

RobSampsonCommented:
Hi, something like this should work.

Regards,

Rob.
intSeconds = 30
Set objShell = CreateObject("WScript.Shell")
objShell.Run "shutdown -r -t " & intSeconds, 1, False
intReturn = objShell.Popup("Do you want to abort the shutdown?", intSeconds, "Abort shutdown?", vbYesNo)
If intReturn = 6 Then
	objShell.Run "shutdown -a", 1, True
End If

Open in new window

MazdajaiAuthor Commented:
Is it possible to bring the popup window to the front? The shutdown window is currently blocking the dialog box...

Thanks.
MazdajaiAuthor Commented:
...Or position the popup window so the users can see it at a glance?
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

MazdajaiAuthor Commented:
Adding vbSystemModal solved the problem. Thanks.
MazdajaiAuthor Commented:
Wait....Using a shortcut to call the vbs place the popup behind again...
RobSampsonCommented:
If you just add a small wait before this line:
intReturn = objShell.Popup("Do you want to abort the shutdown?", intSeconds, "Abort shutdown?", vbYesNo)

by putting this
WScript.Sleep 1000

does that help?

Rob.

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
MazdajaiAuthor Commented:
Rob,

Yes it does help. Thanks!
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.