A Shell() Like Function

Here is a Shell() like function that waits for the process to end before continuing the script execution. Example...

: RunProcess "c:\winnt\notepad.exe" Enjoy! Martin Roy Option Explicit Public Const NORMAL_PRIORITY_CLASS = &H20& Public Const INFINITE = -1& Public Type STARTUPINFO cb As Long lpReserved As String lpDesktop As String lpTitle As String dwX As Long dwY As Long dwXSize As Long dwYSize As Long dwXCountChars As Long dwYCountChars As Long dwFillAttribute As Long dwFlags As Long wShowWindow As Long cbReserved2 As Long lpReserved2 As Long hStdInput As Long hStdOutput As Long hStdError As Long End Type Public Type PROCESS_INFORMATION hProcess As Long hThread As Long dwProcessId As Long dwThreadID As Long End Type Declare Function CreateProcessA Lib "kernel32" _ (Byval lpAppName As Long, _ Byval lpCommandLine As String, _ Byval lpProcessAttributes As Long, _ Byval lpThreadAttributes As Long, _ Byval bInheritHandles As Long, _ Byval dwCreationFlags As Long, _ Byval lpEnvironment As Long, _ Byval lpCurrentDirectory As Long, _ lpStartupInfo As STARTUPINFO, _ lpProcessInformation As PROCESS_INFORMATION) As Long Declare Function WaitForSingleObject Lib "kernel32" (Byval hHandle As Long, Byval dwMilliseconds As Long) As Long Declare Function CloseHandle Lib "kernel32" (Byval hObject As Long) As Long Public Sub RunProcess (cmdline As String) Dim proc As PROCESS_INFORMATION Dim start As STARTUPINFO Dim r As Long start.cb = Len(start) 'Start the application Call CreateProcessA(0&, cmdline, 0&, 0&, 1&, _ NORMAL_PRIORITY_CLASS, 0&, 0&, _ start, proc) 'Wait for the application to end Call WaitForSingleObject(proc.hProcess, INFINITE) 'Close the handle to the process Call CloseHandle(proc.hProcess) End Sub

This was first published in November 2000
This Content Component encountered an error



Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:




  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...