Ну все, наконец-то! Как было сказано в топике
http://bbs.vbstreets.ru/viewtopic.php?t=6889, так и сделал!
Теперь значит если кому надо кикать процессы в ХР, то хватайте, проверено:
- Код: Выделить всё
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Const MAX_PATH = 260
Private Const PROCESS_TERMINATE = &H1
Private Const TH32CS_SNAPHEAPLIST = &H1
Private Const TH32CS_SNAPPROCESS = &H2
Private Const TH32CS_SNAPTHREAD = &H4
Private Const TH32CS_SNAPMODULE = &H8
Private Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
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
Function GetApp(sAppFile As String, Optional Terminate As Boolean = False) As Boolean
On Error Resume Next
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim sFileName As String
Dim lFLenght As Long
Dim lhProcess As Long
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
rProcessFound = Process32First(hSnapShot, uProcess)
Do While rProcessFound
sFileName = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, _
InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0))
lFLenght = Len(sFileName)
If LCase(sFileName) = LCase(Right(sAppFile, lFLenght)) Then
If Terminate Then
lhProcess = OpenProcess(PROCESS_TERMINATE, False, uProcess.th32ProcessID)
TerminateProcess lhProcess, 0&
CloseHandle lhProcess
End If
GetApp = True
End If
rProcessFound = Process32Next(hSnapShot, uProcess)
Loop
CloseHandle hSnapShot
End Function
Использование:
bRet = GetApp("c:\windows\explorer.exe", True)
bRet =
True ' Если процесс есть или был запущен
bRet =
False ' Процесс не запущен
vbskb_api vbskb_process vbskb_terminate