Get Return Code with CreateProcessWithLogonW


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Get Return Code with CreateProcessWithLogonW

  1. #1
    Join Date
    Mar 2005
    Posts
    2

    Get Return Code with CreateProcessWithLogonW

    Hello. I am currently creating a new process from within my vb app using CreateProcessWithLogonW. This command runs another vb app that i created and waits for it to finish. I would like to know how I can get the return code from that child process after it finishes?

    The process it calls, returns values using "ExitProcess errornum", and I can't figure out how to get that value back to the calling app.

    Thank you. Any help is appreciated.

    Here is the funtion I'm using to run the process:

    Code:
    Public Function W2KRunAsUser(ByVal UserName As String, _
            ByVal Password As String, _
            ByVal DomainName As String, _
            ByVal CommandLine As String, _
            ByVal CurrentDirectory As String) As Long
    
        Dim si As STARTUPINFO
        Dim pi As PROCESS_INFORMATION
        
        Dim wUser As String
        Dim wDomain As String
        Dim wPassword As String
        Dim wCommandLine As String
        Dim wCurrentDir As String
        
        Dim Result As Long
        Dim lRunas As Long
        
        si.cb = Len(si)
            
        wUser = StrConv(UserName + Chr$(0), vbUnicode)
        wDomain = StrConv(DomainName + Chr$(0), vbUnicode)
        wPassword = StrConv(Password + Chr$(0), vbUnicode)
        wCommandLine = StrConv(CommandLine + Chr$(0), vbUnicode)
        wCurrentDir = StrConv(CurrentDirectory + Chr$(0), vbUnicode)
          
        Result = CreateProcessWithLogonW(wUser, wDomain, wPassword, _
              LOGON_WITH_PROFILE, 0&, wCommandLine, _
              CREATE_DEFAULT_ERROR_MODE, 0&, wCurrentDir, si, pi)
        DoEvents
        Do
            'Check every 2 seconds to see if process is done
            lRunas = WaitForSingleObject(pi.hProcess, 250)
            DoEvents
        Loop Until (lRunas = 0 Or lRunas = -1)
            
        If Result <> 0 Then
            CloseHandle pi.hThread
            CloseHandle pi.hProcess
            W2KRunAsUser = 0
        Else
            W2KRunAsUser = Err.LastDllError
            MsgBox "CreateProcessWithLogonW() failed with error " & Err.LastDllError, vbExclamation
        End If
    
    End Function
    Last edited by flux113; 06-22-2006 at 11:47 AM.

  2. #2
    Join Date
    Mar 2005
    Posts
    2

    Solution Found.

    I just found out the answer to my question so I figured I'd post the solution here.

    Code:
    Private Declare Function GetExitCodeProcess Lib "kernel32" _
            (ByVal hProcess As Long, lpExitCode As Long) As Long
    That function allowed me to retrieve the exit code from the process I launched by just providing it with the process information.

Similar Threads

  1. Getting a GUI to run
    By Eric in forum Java
    Replies: 4
    Last Post: 04-14-2006, 09:09 AM
  2. VS.Net and Code Behind
    By Chaitanya Marvici in forum ASP.NET
    Replies: 6
    Last Post: 07-21-2003, 09:15 AM
  3. .NET equals Efficiency
    By Kevin in forum .NET
    Replies: 150
    Last Post: 03-04-2002, 05:40 PM
  4. Getting a GUI to function
    By Eric in forum Java
    Replies: 1
    Last Post: 11-27-2001, 06:53 AM
  5. send email
    By marina in forum Java
    Replies: 1
    Last Post: 03-12-2001, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center