user3067193
user3067193

Reputation: 335

VBscript run cmd and wait for output

I'm trying to read a user's PKI card data with Certutil and dump the data to a text file. The idea is to put this as part of a login script to gather some data on user's with expiring certificates.

Here is my code section:

set oShell = WScript.CreateObject("WScript.Shell")
strcommand = "cmd /c certutil -scinfo -silent > " & StrPath
oShell.Run strcommand, true

it seems to work, dumping the cert data to a text file (strpath variable), but once I add more lines to the script it never waits for the command window to finish. It just closes in a fraction of a second or so. I know it takes aobut 7 seconds to read the PKI Card. I've tried sleep as well as a do/while loop and nothing seems to allow the command window run its course. I've also tried the various intwindowstyle options listed here.

Appreciate any help.

Upvotes: 0

Views: 3052

Answers (1)

John Coleman
John Coleman

Reputation: 52008

oShell.Run strcommand, ,true should work. The second argument is the intWindowStyle argument, not bWaitOnReturn. You could also use

oShell.Run strcommand, bWaitOnReturn := true

If this doesn't work, you could try to use the Exec Method . The documentation that this link leads to has a nice example of using a loop with sleep that runs until the process finishes.

Upvotes: 1

Related Questions