vbscript - Yes/no shut down -
i playing vbscript , want make msgbox asks user if want shut down computer or not.
if user clicks yes
should see msgbox first computer starts shutdown.
i using code doesn't work.
what problem?
result = msgbox ("shutdown?", vbyesno, "yes/no exm") select case result case vbyes msgbox("shuting down ...") option explicit dim objshell set objshell = wscript.createobject("wscript.shell") objshell.run "c:\windows\system32\shutdown.exe -r -t 0" case vbno msgbox("ok") end select
as documented option explicit
must appear before other statement in script. using anywhere else in script should raise "expected statement" error pointing line option explicit
statement. if don't error, have on error resume next
in code didn't show.
if move option explicit
statement beginning of script, shutdown still doesn't occur, need check return value of shutdown
command:
rc = objshell.run "c:\windows\system32\shutdown.exe -r -t 0", 0, true if rc <> 0 msgbox "shutdown failed exit code " & rc & "."
the parentheses in msgbox
statements shouldn't cause issue long pass single argument function, i'd still remove them.
Comments
Post a Comment