Basically I Shutdown my PC using shutdown timer in cmd. That is,
Shutdown -s -t xxx
(where xxx being the seconds I enter. Example, Shutdown -s -t 3600
, which means in 1 hour my PC will shutdown automatically).
Now I want to write a VBS where I will enter Seconds in inputbox and those seconds will be put into run the command. But i am unable to run the command successfully.
Below is my code:
Option Explicit
Dim obj,a,x
Set obj=CreateObject("WScript.Shell")
a=InputBox("Enter time in Seconds")
obj.Run "shutdown -s -t"&a
Set obj=Nothing
答案 0 :(得分:0)
Do you need a space between -t and the time?
obj.Run "shutdown -s -t " & a
And because you're destroying the Shell object, try adding this:
obj.Sleep a * 1000 + 1000
Just after obj.Run ...
, but before Set obj = Nothing
and see if keeping the Shell object alive allows the command to complete.