Как узнать, когда завершилось
запущенное приложение? |
Top
|
Option Explicit
Const INFINITE = &HFFFF
'StartupInfo constants
Public Const STARTF_FORCEOFFFEEDBACK = &H80
Public Const STARTF_FORCEONFEEDBACK = &H40
Public Const STARTF_RUNFULLSCREEN = &H20
Public Const STARTF_USECOUNTCHARS = &H8
Public Const STARTF_USEFILLATTRIBUTE = &H10
Public Const STARTF_USEPOSITION = &H4
Public Const STARTF_USESHOWWINDOW = &H1
Public Const STARTF_USESIZE = &H2
Public Const STARTF_USESTDHANDLES = &H100
'ShowWindow constants
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
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
Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA"_
(ByVal lpApplicationName As String, ByVal lpCommandLine As String,
lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal
bInheritHandles As Long, ByVal dwCreationFlags As Long,_
lpEnvironment As Any, ByVal lpCurrentDriectory As String,_
lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32"_
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
'
Public Function RunAndWait(ComLine As String,_
DefaultDir As String, ShowFlag As VbAppWinStyle) As Boolean
Dim si As STARTUPINFO
Dim pi As PROCESS_INFORMATION
si.wShowWindow = ShowFlag
si.dwFlags = STARTF_USESHOWWINDOW
If CreateProcess(vbNullString, ComLine, ByVal 0&, ByVal 0&,_
False, 0, ByVal 0&, DefaultDir, si, pi) Then
WaitForSingleObject pi.hProcess, INFINITE
CloseHandle pi.hProcess
RunAndWait = True
Exit Function
End If
RunAndWait = False
End Function
Использование:
If RunAndWait("rar.exe a regbackup system.dat user.dat", "c:\windows", vbNormalFocus) Then
MsgBox "Registry backuped!"
End
ОБСУДИТЬ СТАТЬЮ
НА ФОРУМЕ