calling an exe from vb.net

D

Dave Cullen

What's the correct way to run an external .exe file from within a VB.NET
app?
I had used code like below in VB6 before, but it doesn't work in .NET.
Anybody have an equivalent?

'Function for executing an exe from VB6

Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
 
H

Herfried K. Wagner [MVP]

* Dave Cullen said:
What's the correct way to run an external .exe file from within a VB.NET
app?
I had used code like below in VB6 before, but it doesn't work in .NET.
Anybody have an equivalent?

Have a look at the 'System.Diagnostics.Process' class and at the
'ProcessStartInfo' class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top