When you use the command, Ret = Shell("file.exe", vbNormalFocus) the variable "Ret" will hold the PID number to the now running EXE right?
So what APIs can you use to launch an EXE and get back its PID (or Hwnd) instantly?
Printable View
When you use the command, Ret = Shell("file.exe", vbNormalFocus) the variable "Ret" will hold the PID number to the now running EXE right?
So what APIs can you use to launch an EXE and get back its PID (or Hwnd) instantly?
The CreateProcess API will return the Process ID and a handle to the created process in the Process_Information structure.
OK thanks! :) I got this code to return the PID for the EXE + command line I launch, but I'm unsure what to close after calling it? Does this look right?Quote:
Originally Posted by Doogle
Code:Public Function ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret&
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Return the PID
ExecCmd = proc.dwProcessID
' ??? Close handles ????
Call CloseHandle(proc.hThread) ' ???
Call CloseHandle(proc.hProcess) '???
End Function
Looks Ok to me, (You don't need the 'Call' for the CloseHandle API)
Code:CloseHandle(proc.hThread)
CloseHandle(proc.hProcess)
Thanks for the help!:wave:Quote:
Originally Posted by Doogle