-1

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
2
  • Answer hasn't been accepted by clearly a duplicate of Run Command Line & Command From VBS Commented Sep 14, 2015 at 16:11
  • How about the at least specify what error you received as @Yimin could have simply pointed out in the comments you have a missing space between -t"&a should be -t " & a. Commented Sep 14, 2015 at 16:34

1 Answer 1

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 = Nothingand see if keeping the Shell object alive allows the command to complete.

Sign up to request clarification or add additional context in comments.

10 Comments

Both dashes and forward slashes are acceptable. Give it a try.
No Buddy. Its not working yet...
@MohammedSajjad - Might be because you're destroying the object and exiting the script. I read up and it doesn't look like the operation is queued. Have updated answer.
@Lankymart - read up on shutdown, it's one of the reverse ones, dashes implemented before slashes! Have removed the suggestion.
@MohammedSajjad Before you can expect us to help you update your question and tell us what error you are getting. Saying it doesn't work tells us nothing be descriptive. Lets face it we can't read minds.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.