質問

I am trying to execute a batch command from within vbscript.

I want the output to be written to a file.

When I run it, I get no output to the console or to the file.

I'm trying:

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

What am I doing wrong?

When I run the wmic command in a command prompt it works well.

役に立ちましたか?

解決

I needed to add cmd in front of the command such as:

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

in addition to using the cmd keyword there are also several switches you can use depending on your needs. You can see them by typing cmd /? in a command prompt window.

Here are a couple:

/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"

Modify for this

command = "cmd wmic product get Name >> textfile.txt"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top