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 


VB Script

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon
David Johnson, CD

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

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

Do While oExec.Status = 0
     WScript.Sleep 100

WScript.Echo oExec.ExitCode

Open in new window

Bill Prew

I think you should just be able to do:

rtn = WshShell.run(strCommand,,True)

Open in new window


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:
CertUtil: -hashfile command completed successfully.

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

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
David Johnson, CD

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

David -- I think that's It
Thanks All  

Bill Prew

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.