|
-
Mar 11th, 2008, 12:00 AM
#1
[RESOLVED] API equivlent of "Ret=Shell"
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?
-
Mar 11th, 2008, 12:23 AM
#2
Re: API equivlent of "Ret=Shell"
The CreateProcess API will return the Process ID and a handle to the created process in the Process_Information structure.
-
Mar 11th, 2008, 12:56 AM
#3
Re: API equivlent of "Ret=Shell"
 Originally Posted by Doogle
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?
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
-
Mar 11th, 2008, 01:19 AM
#4
Re: API equivlent of "Ret=Shell"
Looks Ok to me, (You don't need the 'Call' for the CloseHandle API)
Code:
CloseHandle(proc.hThread)
CloseHandle(proc.hProcess)
-
Mar 11th, 2008, 01:25 AM
#5
Re: API equivlent of "Ret=Shell"
 Originally Posted by Doogle
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|