1

Okay I created a small script to call "net file" and pump the output to a file. There are no spaces in the filenames, and everything seems okay when I run it interactively. So I run the following and I get no results and no errors:

set oWShell = CreateObject("WScript.Shell")
owshell.run "net file > C:\openfiles.txt"
Set owShell = nothing

Now if modify this just slightly to show execute the same command (and keep my command window open) it works just as expected (except it keeps the cmd window open which I can't have)

set oWShell = CreateObject("WScript.Shell")
owshell.run "%comspec% /k net file > C:\openfiles.txt"
Set owShell = nothing

It must be something obvious that I'm just missing. I only touch vbs once in a blue moon so it isn't something that I'm that used to using.

Any help would be appreciated! Thanks in advance!

1
  • Sorry, I didnt understood: what's the matter? No output? Commented Dec 1, 2011 at 20:56

2 Answers 2

2

You need a shell (i.e. %comspec%) to get shell features like redirection; the persisten window is what you asked for: the /k lets the shell stay open (try /c instead) and you should use the second and third parameter of the .Run method to get a hidden window (and possibly wait for the process before you zap the owShell).

Sign up to request clarification or add additional context in comments.

Comments

0

Have a look at Run. Changing

owshell.run "%comspec% /k net file > C:\openfiles.txt"

to

owshell.run "%comspec% /c net file > C:\openfiles.txt", 0, FALSE

This will hide the cmd and carry on with the rest of the script... If you want to wait for the command to finish, change FALSE to TRUE.

Also keep in mind that some machines are funny about letting you write files directly to C:\. Possibly create a test folder and write to there instead!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.