Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi. I want to use VB.net to execute a program (*.exe file), wait till it finishes and get the return value the *.exe program returns. Now I did accomplish this using the code bellow however the error code i get the first few tries is correct but then i keep getting 0xCDCDCDCD as the error code. I don't understand why running this code would generate the wrong result after few tries. Please help.
How can i ensure i get the correct exit code
Ps. the *.exe file was writen in c++ and it always returns a positive integer where as 0xCDCDCDCD is negative as a signed integer representation

CODE:
VB
Dim startInfo As New System.Diagnostics.ProcessStartInfo
Dim MyProces As Process

startInfo.FileName = myExeFileName
startInfo.Arguments = myExeArgString
startInfo.CreateNoWindow = True
startInfo.UseShellExecute = True
startInfo.WindowStyle = ProcessWindowStyle.Hidden

MyProces = Process.Start(startInfo)
MyProces.WaitForExit()

If (MyProces.ExitCode <> 0) Then
  MsgBox("0x" + Hex(MyProces.ExitCode()))
End If
Posted
Updated 28-Aug-17 4:16am
v2

1 solution

The Process class has an ExitCode property. Example here[^].

I think that is what you need. :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 3-Mar-11 21:47pm    
Yes, that's it, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900