I use the following code to launch a windows app (can launch most any app),
but the loadapp.exe geneated takes the whole command line and passes it to
dvShell() function (posted in the source code forum) which lauches the process and wait infinitely for
the process to finish. When the process does finish it takes the error
code and sets the exit code to 255 or less. (DOS errorlevel will only return
a value of 255 or less.)
If you need the exe then send me an email at [email protected]
Code:
rem Ex: batch file loadapp.exe pbdllapp.exe /parameter1 /parameter1 if not errorlevel 1 echo there was NO ERROR. if errorlevel 1 echo there was an ERROR!!!! of 1 or higher if errorlevel 100 echo there was an ERROR!!!! of 100 or higher rem end batchfile 'PBCC #INCLUDE "\pb\winapi\WIN32API.INC" ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' dvShell - Returns errorlevel of process and launches process. ' ' CmdLine$=command line and parameters passed that should be launched ' ShowWind&=default window state of lauched program. ' %SW_HIDE ' %SW_SHOWNORMAL ' %SW_NORMAL ' %SW_SHOWMINIMIZED ' %SW_SHOWMAXIMIZED ' %SW_MAXIMIZE ' %SW_SHOWNOACTIVATE ' %SW_SHOW ' %SW_MINIMIZE ' %SW_SHOWMINNOACTIVE ' %SW_SHOWNA ' %SW_RESTORE ' %SW_SHOWDEFAULT ' %SW_MAX ' TimeLimit&=milliseconds windows will wait for prcoess to finish. ' passing %INFINITE will tell windows to wait forever. ' ' Usage - if App_PrevInstance("aljsdlkajsdljasdlkjasldkj") then <Another instance ' is running> ' FUNCTION dvShell(BYVAL CmdLine$, BYVAL ShowWind&, BYVAL TimeLimit&) as long LOCAL Si AS STARTUPINFO LOCAL Pi AS PROCESS_INFORMATION Si.cb = SIZEOF(Si) Si.dwFlags = %STARTF_USESHOWWINDOW Si.wShowWindow = ShowWind& IF CreateProcess("", _ BYVAL STRPTR (CmdLine$), _ BYVAL %NULL, _ BYVAL %NULL, _ 0, _ %NORMAL_PRIORITY_CLASS, _ BYVAL %NULL, _ BYVAL %NULL, _ Si, _ Pi) THEN CALL WaitForInputIdle(pi.hProcess, %INFINITE) IF TimeLimit& THEN CALL WaitForSingleObject(pi.hProcess, TimeLimit&) 'Ec&=256 rc& = GetExitCodeProcess(pi.hProcess,Ec&) FUNCTION=Ec& CALL CloseHandle(pi.hProcess) CALL CloseHandle(pi.hThread) END IF END IF END FUNCTION Function PBMain() as long ret&=dvshell(command$,1,%INFINITE) if ret&>255 then function=255 else function=ret& end if end function
James Moneypenny
[This message has been edited by James Moneypenny (edited July 15, 2001).]
Leave a comment: