2013-06-28 45 views
1

我試圖從VBScript中執行批處理命令。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

我需要在命令前加上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

你應該使用'CMD/C ...'不只是'CMD ...'。 –

+0

我不使用/ C在我的實際腳本,但不作出正確的在所有情況下。我想保持答案一般。 – ajon

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

修改此

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