vbscript执行命令到文件

时间:2013-06-28 23:06:18

标签: 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

我做错了什么?

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

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:-2)

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

修改此

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