Attribute VB_Name = "mdlShell"
'/*********************************************************************************
'
' サブプログラムの起動モジュールです。
' 作成者:
'
'----------------------------------------------------------------------------------
' 修正履歴 修正者 内容
' 作成日: 平成14年7月23日 王 群 新規作成
'
'
'**********************************************************************************/
Option Explicit
Private isShellRight As Boolean
' API関数宣言
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
' フォーム状態の定数宣言
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
' プロセスについてのAPI関数宣言
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwAccess As Long, ByVal lpCommandLine As Long, ByVal IDProcess As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal lpdExitCode As Long, hHandle As Long) As Boolean
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Boolean
' プロセスについての定数宣言
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STILL_ACTIVE = &H103
' SHELLのプロセスを監視して、終了待ちを行う
' @parameter strprogram プログラム名
' @parameter strparameter パラメータ
Public Sub WaitShell(ByVal strprogram As String, ByVal strparameter As String)
isShellRight = True
On Error GoTo ErrWaitShell
Dim hShell As Long
Dim hProc As Long
Dim lExit As Long
Dim bret As Boolean
' プログラムの実行
Dim strcmdline As String
If strparameter = "" Then
strcmdline = strprogram
Else
strcmdline = strprogram & " " & strparameter
End If
hShell = Shell(strcmdline, vbNormalFocus)
' プロセスの終了待ち
Do
If GetExitCodeProcess(hProc, lExit) = False Then Exit Sub
Call Sleep(100)
DoEvents
Loop While lExit = STILL_ACTIVE
' ハンドルのクローズ
bret = CloseHandle(hProc)
Exit Sub
ErrWaitShell:
isShellRight = False
If Err.Number = 53 Or Err.Number = 76 Then
MsgBox "ウフミ・""" & strprogram & """ ボキィニッ」。", vbCritical
Else
MsgBox Err.Description
End If
End Sub
' OCRについてのSHELLのプロセスを監視して、終了待ちを行う
' @parameter strprogram プログラム名
' @parameter strparameter パラメータ
Public Function OcrWaitShell(ByVal strprogram As String, ByVal strparameter As String) As Boolean
Call WaitShell(strprogram, strparameter)
OcrWaitShell = isShellRight
End Function
CreateProcess()启动进程,其中有一个参数可以指定进程的优先级。
给你一小段代码:
Attribute VB_Name = "mdlShell"
'/*********************************************************************************
'
' ƒTƒuƒvƒƒOƒ‰ƒ€‚Ì‹N“®ƒ‚ƒWƒ…[ƒ‹‚Å‚·B
' 쬎ÒF@‰¤ŒQ
'
'----------------------------------------------------------------------------------
' C³—š—ð C³ŽÒ “à—e
' 쬓úF@•½¬‚P‚S”N‚VŒŽ‚Q‚R“ú ‰¤@ŒQ V‹Kì¬
'
'
'**********************************************************************************/
Option Explicit
Private isShellRight As Boolean
' ‚`‚o‚hŠÖ”錾
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
' ƒtƒH[ƒ€ó‘Ô‚Ì’è”錾
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
' ƒvƒƒZƒX‚ɂ‚¢‚Ä‚Ì‚`‚o‚hŠÖ”錾
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwAccess As Long, ByVal lpCommandLine As Long, ByVal IDProcess As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal lpdExitCode As Long, hHandle As Long) As Boolean
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Boolean
' ƒvƒƒZƒX‚ɂ‚¢‚Ä‚Ì’è”錾
Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STILL_ACTIVE = &H103
' ‚r‚g‚d‚k‚k‚̃vƒƒZƒX‚ðŠÄŽ‹‚µ‚ÄAI—¹‘Ò‚¿‚ðs‚¤
' @parameter strprogram ƒvƒƒOƒ‰ƒ€–¼
' @parameter strparameter ƒpƒ‰ƒ[ƒ^
Public Sub WaitShell(ByVal strprogram As String, ByVal strparameter As String)
isShellRight = True
On Error GoTo ErrWaitShell
Dim hShell As Long
Dim hProc As Long
Dim lExit As Long
Dim bret As Boolean
' ƒvƒƒOƒ‰ƒ€‚ÌŽÀs
Dim strcmdline As String
If strparameter = "" Then
strcmdline = strprogram
Else
strcmdline = strprogram & " " & strparameter
End If
hShell = Shell(strcmdline, vbNormalFocus)
' ƒvƒƒZƒX‚ÌI—¹‘Ò‚¿
Do
If GetExitCodeProcess(hProc, lExit) = False Then Exit Sub
Call Sleep(100)
DoEvents
Loop While lExit = STILL_ACTIVE
' ƒnƒ“ƒhƒ‹‚̃Nƒ[ƒY
bret = CloseHandle(hProc)
Exit Sub
ErrWaitShell:
isShellRight = False
If Err.Number = 53 Or Err.Number = 76 Then
MsgBox "³ÌÐò """ & strprogram & """ ÎÞ·¨Æô¶¯£¡", vbCritical
Else
MsgBox Err.Description
End If
End Sub
' ‚n‚b‚q‚ɂ‚¢‚Ä‚Ì‚r‚g‚d‚k‚k‚̃vƒƒZƒX‚ðŠÄŽ‹‚µ‚ÄAI—¹‘Ò‚¿‚ðs‚¤
' @parameter strprogram ƒvƒƒOƒ‰ƒ€–¼
' @parameter strparameter ƒpƒ‰ƒ[ƒ^
Public Function OcrWaitShell(ByVal strprogram As String, ByVal strparameter As String) As Boolean
Call WaitShell(strprogram, strparameter)
OcrWaitShell = isShellRight
End Function