Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Have a look at <a href="http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx" rel="noreferrer">WaitForSingleObject</a> and <a href="http://msdn.microsoft.com/en-us/library/ms683189(VS.85).aspx" rel="noreferrer">GetExitCodeProcess</a> functions.</p> <p>Example Usage:</p> <pre><code>Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long Public Const INFINITE = &amp;HFFFF Public Const PROCESS_ALL_ACCESS = &amp;H1F0FFF Sub RunApplication(ByVal Cmd as String) lTaskID = Shell(Cmd, vbNormalFocus) //Get process handle lPID = OpenProcess(PROCESS_ALL_ACCESS, True, lTaskID) If lPID Then //Wait for process to finish Call WaitForSingleObject(lPID, INFINITE) //Get Exit Process If GetExitCodeProcess(lPID, lExitCode) Then //Received value MsgBox "Successfully returned " &amp; lExitCode, vbInformation Else MsgBox "Failed: " &amp; DLLErrorText(Err.LastDllError), vbCritical End If Else MsgBox "Failed: " &amp; DLLErrorText(Err.LastDllError), vbCritical End If lTaskID = CloseHandle(lPID) End Sub Public Function DLLErrorText(ByVal lLastDLLError As Long) As String Dim sBuff As String * 256 Dim lCount As Long Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &amp;H100, FORMAT_MESSAGE_ARGUMENT_ARRAY = &amp;H2000 Const FORMAT_MESSAGE_FROM_HMODULE = &amp;H800, FORMAT_MESSAGE_FROM_STRING = &amp;H400 Const FORMAT_MESSAGE_FROM_SYSTEM = &amp;H1000, FORMAT_MESSAGE_IGNORE_INSERTS = &amp;H200 Const FORMAT_MESSAGE_MAX_WIDTH_MASK = &amp;HFF lCount = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0, lLastDLLError, 0&amp;, sBuff, Len(sBuff), ByVal 0) If lCount Then DLLErrorText = Left$(sBuff, lCount - 2) \\Remove line feeds End If End Function </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload