Resolved Catching vbscript error in VB.NET

kasteel

Well-known member
Joined
May 29, 2009
Messages
50
Programming Experience
10+
Hi

I know it is possible to run a vbscript from within VB.NET (Visual Studio 2005 / 2008)

Is it possible for VB.NET to catch the vbscript's exit code?

I know it is possible within a HTA:

VB.NET:
If Checkbox2.Checked Then       
Set objWSH = CreateObject("WScript.Shell")
strCMD = "wscript.exe c:\myvbscript.vbs"
Return = objWSH.Run(strCMD,1, True)

If Return = 0 Then

'Do some stuff

Else

'Do some stuff

End If			
End If

But can I do the same with VB.NET just using normal Windows Form Application.

Any help / advice would be appreciated.
 
Last edited:
VB.NET:
Dim p As Process = Process.Start("d:\returncode.vbs")
p.WaitForExit()
Dim code As Integer = p.ExitCode
If the script takes time to finish you should use Exited event (or a secondary thread) instead of WaitForExit blocking the UI thread.
Process Class (System.Diagnostics)
 

Latest posts

Back
Top