如何在 VBScript 中 运行 命令提示符?
How to run command prompt in VBScript?
基本上我在 cmd 中使用关机计时器关闭我的电脑。
也就是说,
Shutdown -s -t xxx
(其中 xxx 是我输入的秒数。例如,Shutdown -s -t 3600
,这意味着我的电脑将在 1 小时后自动关机)。
现在我想编写一个 VBS,我将在输入框中输入秒数,这些秒数将被放入 运行 命令中。但是我无法 运行 命令成功。
下面是我的代码:
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
-t 和时间之间需要 space 吗?
obj.Run "shutdown -s -t " & a
并且因为您要破坏 Shell 对象,请尝试添加:
obj.Sleep a * 1000 + 1000
就在 obj.Run ...
之后但在 Set obj = Nothing
之前,看看保持 Shell 对象是否允许命令完成。
基本上我在 cmd 中使用关机计时器关闭我的电脑。 也就是说,
Shutdown -s -t xxx
(其中 xxx 是我输入的秒数。例如,Shutdown -s -t 3600
,这意味着我的电脑将在 1 小时后自动关机)。
现在我想编写一个 VBS,我将在输入框中输入秒数,这些秒数将被放入 运行 命令中。但是我无法 运行 命令成功。
下面是我的代码:
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
-t 和时间之间需要 space 吗?
obj.Run "shutdown -s -t " & a
并且因为您要破坏 Shell 对象,请尝试添加:
obj.Sleep a * 1000 + 1000
就在 obj.Run ...
之后但在 Set obj = Nothing
之前,看看保持 Shell 对象是否允许命令完成。