Link to home
Start Free TrialLog in
Avatar of KzKrew
KzKrewFlag for United States of America

asked on

Save return value of .EXE to VBS Variable

How can i save the output value of
certutil.exe -hashfile C:\TestFolder\test.txt MD5"
to a VBS variable.
Certutil.exe is a command-line program, installed as part of Certificate Services.

Assume i need to do something like this 

Dim WshShell
Set WshShell = CreateObject("WScript.Shell") strCommand = "certutil.exe -hashfile C:\TestFolder\Test.txt MD5" WshShell.run strCommand

Open in new window


But how do i get the value out and assign to vbs variable 

Dan



Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("csharpprocess.exe")

Do While oExec.Status = 0
     WScript.Sleep 100
Loop

WScript.Echo oExec.ExitCode

Open in new window

Avatar of Bill Prew
Bill Prew

I think you should just be able to do:

rtn = WshShell.run(strCommand,,True)

Open in new window


»bp
Avatar of KzKrew

ASKER

Ok -- have this somewhat working with the following changes
Dim WshShell

set WshShell = CreateObject("Wscript.Shell")

set strCommand = WshShell.Exec("certutil.exe -hashfile C:\TestFolder\Test.txt MD5")
strResult = strCommand.StdOut.ReadAll
WScript.Echo strResult

Open in new window

Get the following result
MD5 hash of C:\TestFolder\Test.txt:
5a511e9d34a7aac2b9d9906df9c1b3b0
CertUtil: -hashfile command completed successfully.

How can i just assign the 5a511e9d34a7aac2b9d9906df9c1b3b0 hash to a vbs variable
Dan

ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KzKrew

ASKER

David -- I think that's It
Thanks All  

Just for posterity, when I read the question I thought you were just looking to capture the exit code of the EXE file you were executing, typically referred to as ERRORLEVEL.  But it sounds / looks like you were actually looking to capture the text output of the EXE, typically what is referred to as STDOUT.

Glad you got a solution to what you needed.


»bp