-
Hey!
How can I know when a Ms-DOS Application launch in by the shell command is done? In this example, I want the program PURGE accomplich is job then the will complete the FOR...NEXT instructions.
Ex:
[CODE]
Private sub CmdOk_Click()
for i = 0 to list1.listcount - 1
cmd$ = "PURGE /DATA "+chr$(34)+list1.list(i)+chr$(34)
shell cmd, vbhide
next i
msgbox "Done.", vbinformations
end sub
------------
ICQ: 65287451
E-MAIL: [email protected]
Homepage: http://www.sx3k.le-site.net
AIM: MBR5520
Running VB5 Enterprise Edition Service Pack 2
------------
-
-
Try something like this:
Code:
Private 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
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private 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
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1
Public Sub ExecuteCommandLine(p_strCommandLine As String)
Dim tProcInfo As PROCESS_INFORMATION
Dim tStartInfo As STARTUPINFO
Dim lngRet As Long
tStartInfo.cb = Len(start)
lngRet = CreateProcessA(0&, p_strCommandLine, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, tStartInfo, tProcInfo)
'Wait while the shelled application is finished
lngRet = WaitForSingleObject(tProcInfo.hProcess, INFINITE)
lngRet = CloseHandle(tProcInfo.hProcess)
End Sub
Then you can use this sub routine like this:
Code:
Private Sub Command1_Click()
Dim i As Integer
Dim strCommandLine As String
For i = 0 To List1.ListCount - 1
strCommandLine = "PURGE /DATA " + Chr(34) + List1.List(i) + Chr(34)
ExecuteCommandLine strCommandLine
Next
MsgBox "Done.", vbinformations
End Sub