Batch file vbscript将命令执行到文件

Batch file vbscript将命令执行到文件,batch-file,vbscript,wmic,Batch File,Vbscript,Wmic,我正在尝试从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 我做

我正在尝试从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
命令时,它运行良好。

我需要在命令前面添加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
为此进行修改

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

您应该使用
cmd/c…
而不仅仅是
cmd…
。我在实际脚本中确实使用了/c,但这并不能使它在所有情况下都正确。我想保持答案的概括性。
command = "cmd wmic product get Name >> textfile.txt"