Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can catch the error level if you are that the command will return 0 on success: <a href="http://www.devx.com/vb2themax/Tip/18663" rel="nofollow noreferrer">http://www.devx.com/vb2themax/Tip/18663</a></p> <blockquote> <h1>Get the exit code of a process</h1> <p>In a few cases, in particular when running MsDos batch files from within a VB application, you may want to determine the <code>ERRORLEVEL</code> set by an external application. You can't do it with a plain Shell statement, but the job becomes easy with the support of the <code>GetProcessExitCode</code> API function:</p> <pre><code>Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds 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 GetExitCodeProcess Lib "kernel32" (ByVal hProcess As _ Long, lpExitCode As Long) As Long Const STILL_ACTIVE = &amp;H103 Const PROCESS_QUERY_INFORMATION = &amp;H400 Private Sub cmdRunNotepad_Click() Dim hTask As Long Dim hProcess As Long Dim exitCode As Long hTask = Shell("Notepad", vbNormalFocus) hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hTask) ' loop until the process returns a valid exit code Do ' relinquish this CPU time slice Sleep 100 DoEvents ' query for exit code GetExitCodeProcess hProcess, exitCode Loop While exitCode = STILL_ACTIVE MsgBox "Exit code = " &amp; exitCode, vbInformation End Sub </code></pre> <p>Francesco Balena</p> </blockquote> <p>or you can try something like this:</p> <pre><code>myRes = Shell("cmd /c myScript.cmd&amp;&amp;echo success") </code></pre> <p>here's more info about conditional execution: <a href="http://www.robvanderwoude.com/condexec.php" rel="nofollow noreferrer">http://www.robvanderwoude.com/condexec.php</a></p> <p>But in both cases you rely on exit codes.</p>
    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. 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.
    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