Results 1 to 5 of 5

Thread: [RESOLVED] API equivlent of "Ret=Shell"

  1. #1

    Thread Starter
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Resolved [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?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  3. #3

    Thread Starter
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: API equivlent of "Ret=Shell"

    Quote 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

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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)

  5. #5

    Thread Starter
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: API equivlent of "Ret=Shell"

    Quote 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
  •  



Click Here to Expand Forum to Full Width