1

我正在尝试从 vbscript 中执行批处理命令。

我希望将输出写入文件。

当我运行它时,我没有得到控制台或文件的输出。

我正在努力:

Dim objShell, command
Set objShell = WScript.CreateObject ("WScript.shell")
command = "wmic product get Name > textfile.txt"
objShell.Run command, 0, True 
Set objShell = Nothing

我究竟做错了什么?

当我wmic在命令提示符下运行命令时,它运行良好。

4

2 回答 2

2

我需要在命令前面添加 cmd,例如:

command = "cmd wmic product get Name > textfile.txt"

除了使用 cmd 关键字之外,您还可以根据需要使用几个开关。你可以通过输入 cmd /? 来查看它们。在命令提示符窗口中。

这里有一对:

/C      Carries out the command specified by string and then terminates
/K      Carries out the command specified by string but remains
/S      Modifies the treatment of string after /C or /K (see below)
/Q      Turns echo off
/D      Disable execution of AutoRun commands from registry (see below)
/A      Causes the output of internal commands to a pipe or file to be ANSI
/U      Causes the output of internal commands to a pipe or file to be Unicode
于 2013-06-28T23:27:50.223 回答
-2
command = "cmd wmic product get Name > textfile.txt"

为此修改

command = "cmd wmic product get Name >> textfile.txt"
于 2016-10-21T14:48:05.693 回答