| Код | Private Declare Function Process32First Lib "kernel32.dll" ( _ ByVal hSnapshot As Long, _ ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32.dll" ( _ ByVal hSnapshot As Long, _ ByRef lppe As PROCESSENTRY32) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32.dll" ( _ ByVal dwFlags As Long, _ ByVal th32ProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hPass As Long) As Long
Private Const TH32CS_SNAPPROCESS As Long = &H2 Private Const MAX_PATH As Long = 260&
Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type
Private Function IsProcessLoaded(ProcessName As String) As Boolean Dim hSnapshot As Long, uProcess As PROCESSENTRY32 IsProcessLoaded = False hSnapshot = CreateToolhelp32Snapshot(&H2, 0) If hSnapshot = &HFFFF Then Exit Function uProcess.dwSize = Len(uProcess) Call Process32First(hSnapshot, uProcess) Do If LCase(Left$(uProcess.szExeFile, Len(ProcessName))) = LCase(ProcessName) Then IsProcessLoaded = True Exit Do End If Loop While (Process32Next(hSnapshot, uProcess)) Call CloseHandle(hSnapshot) End Function
Private Sub Form_Load() If IsProcessLoaded("winword.exe") Then MsgBox "Process loaded" Else MsgBox "Process not found" End If End Sub
|
|