Author Topic: IWshExec.ExitCode Property  (Read 3080 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2512
  • User-Rate: +209/-0
IWshExec.ExitCode Property
« on: July 14, 2008, 10:22:27 PM »

The following example illustrates the use of the ExitCode property. It contains an intentionally wrong argument "dire" to return an exit code <> 0.

Code: [Select]
#COMPILE EXE
#DIM ALL
#INCLUDE "WSHOM.INC"

' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN

   LOCAL pWsh3 AS IWshShell3
   LOCAL pWshExec AS IWshExec

   pWsh3 = NEWCOM "WScript.Shell"
   IF ISNOTHING(pWsh3) THEN EXIT FUNCTION
   pWshExec = pWsh3.Exec(UCODE$("%comspec% /c dire"))

   DO
      IF pWshExec.Status <> 0 THEN EXIT DO
      SLEEP 100
   LOOP

   PRINT "Status: " pWshExec.Status
   PRINT "Exit code: " pWshExec.ExitCode

   pWshExec = NOTHING
   pWsh3 = NOTHING

   WAITKEY$

END FUNCTION
' ========================================================================================