怎樣判斷它是否已經執行完成?

JERRY_LIU 2003-11-22 04:21:06
我現在要連續啟動n個外部程序,但我希望能在一個執行完成後,再執行下一個
我要執行的外部程序是winrar,用它來壓縮一些檔案,多時要半個小時,少時幾秒,我要怎樣判斷呢?
如果能做成進度條就最好了.
...全文
40 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
射天狼 2003-11-24
  • 打赏
  • 举报
回复
'这是同步执行的例子
Option Explicit

Const INFINITE As Long = -1&
Const STATUS_WAIT_0 As Long = &H0
Const WAIT_OBJECT_0 As Long = STATUS_WAIT_0
Const NORMAL_PRIORITY_CLASS As Long = &H20&

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As Long
lpDesktop As Long
lpTitle As Long
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 Declare Function WaitForSingleObject Lib "Kernel32" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function InputIdle Lib "user32" Alias "WaitForInputIdle" (ByVal hProcess As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Long) As Long
Private 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

Private Sub Command1_Click()
SyncShell "D:\ProgramsExample\DelphiExample\stk\Stk.exe"
End Sub

Public Function StartProcess(CommandLine As String, Optional Hide As Boolean = False) As Long
Const STARTF_USESHOWWINDOW As Long = &H1
Const SW_HIDE As Long = 0

Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO

'Initialize the STARTUPINFO structure:
Start.cb = Len(Start)
If Hide Then
Start.dwFlags = STARTF_USESHOWWINDOW
Start.wShowWindow = SW_HIDE
End If
'Start the shelled application:
CreateProcessA 0&, CommandLine, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, Start, proc

StartProcess = proc.hProcess
End Function

Public Function SyncShell(CommandLine As String, Optional Timeout As Long, _
Optional WaitForInputIdle As Boolean, Optional Hide As Boolean = False) As Boolean

Dim hProcess As Long

Const STARTF_USESHOWWINDOW As Long = &H1
Const SW_HIDE As Long = 0

Dim ret As Long
Dim nMilliseconds As Long

If Timeout > 0 Then
nMilliseconds = Timeout
Else
nMilliseconds = INFINITE
End If

hProcess = StartProcess(CommandLine, Hide)

If WaitForInputIdle Then
'Wait for the shelled application to finish setting up its UI:
ret = InputIdle(hProcess, nMilliseconds)
Else
'Wait for the shelled application to terminate:
ret = WaitForSingleObject(hProcess, nMilliseconds)
End If

CloseHandle hProcess

'Return True if the application finished. Otherwise it timed out or erred.
SyncShell = (ret = WAIT_OBJECT_0)
End Function
JERRY_LIU 2003-11-24
  • 打赏
  • 举报
回复
我再頂
JERRY_LIU 2003-11-22
  • 打赏
  • 举报
回复
up

是不是周末休息去了......
JERRY_LIU 2003-11-22
  • 打赏
  • 举报
回复
這位老大能說說怎樣來做嗎
我的winrar是用 shell來啟動的,但要啟動下一個時的條件我就不會設了.
rainstormmaster 2003-11-22
  • 打赏
  • 举报
回复
做个shell and wait的程序就行了

7,789

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧