Using The Win Api To Shell A Process And Wait For It To Finish

This example will allow you to shell out to a program and force Notes to wait
for it to finish. In this example, I will use the script to map a network
drive.
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
Public Const SW_MIN = 7
Public Const STARTF_USESHOWWINDOW = &H1

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 Integer
cbReserved2 As Integer
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 WaitForSingleObject Lib "kernel32" (Byval _
hHandle As Long, Byval dwMilliseconds As Long) As Long

Declare Function CreateProcessA Lib "kernel32" (Byval _
lpApplicationName 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 CloseHandle Lib "kernel32" (Byval _
hObject As Long) As Long


Sub Initialize
Dim proc As PROCESS_INFORMATION
Dim StartInf As STARTUPINFO

StartInf.cb = Len(StartInf)
StartInf.dwFlags = STARTF_USESHOWWINDOW
StartInf.wShowWindow = SW_MIN

CMDMap$ = |NET USE Y: \\SERVERNAME\DIRNAME /YES|

RetVal = CreateProcessA(0&, CMDMap$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc) ' Start the Program

RetVal = WaitForSingleObject(proc.hProcess, INFINITE) 'This makes the
process 'System Modal ( can't continue till it's over ).
RetVal = CloseHandle(proc.hProcess) ' Close the Process Handle
RetVal = CloseHandle(proc.hThread) 'Close the Thread

'Do stuff to the new mapping here
.
.
.
'Now Disconnect the drive
CMDMap$ = |NET USE Y: /DELETE /YES|

RetVal = CreateProcessA(0&, CMDMap$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc) ' Start the Program

RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
RetVal = CloseHandle(proc.hProcess) ' Close the Process Handle
RetVal = CloseHandle(proc.hThread) 'Close the Thread

End Sub
This was first published in November 2000

Dig deeper on Domino Resources - Part 7

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWinIT

Search400

  • 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 ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close