主题:关于VB杀进程的问题
使用以下代码可以判断 系统里是否运行了某个进程, 可是 该用什么方法结束 指定的进程呢?
以下是判断进程的代码: (感谢凡尘大虾提供)
第 6 楼
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias _
"Process32First" (ByVal hSnapShot As Long, uProcess _
As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias _
"Process32Next" (ByVal hSnapShot As Long, uProcess _
As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass _
As Long)
Const TH32CS_SNAPPROCESS As Long = 2&
Const MAX_PATH As Integer = 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 Sub Form_Click()
Call GetExeNames
End Sub
Private Sub GetExeNames()
Dim hSnapShot As Long, Result As Long
Dim aa As String, bb As String
Dim Process As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = 0 Then Exit Sub
Process.dwSize = Len(Process)
Result = ProcessFirst(hSnapShot, Process)
Do While Result <> 0
aa = Process.szExeFile
aa = Left$(aa, InStr(aa, Chr$(0)) - 1)
If LCase(aa) = "notepad.exe" Then
MsgBox "发现 记事本 程序在运行"
End
End If
Result = ProcessNext(hSnapShot, Process)
Loop
Call CloseHandle(hSnapShot)
End Sub
Private Sub Form_Load()
Me.Show
Do
DoEvents
Call GetExeNames
Loop
End Sub
以下是判断进程的代码: (感谢凡尘大虾提供)
第 6 楼
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias _
"Process32First" (ByVal hSnapShot As Long, uProcess _
As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias _
"Process32Next" (ByVal hSnapShot As Long, uProcess _
As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass _
As Long)
Const TH32CS_SNAPPROCESS As Long = 2&
Const MAX_PATH As Integer = 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 Sub Form_Click()
Call GetExeNames
End Sub
Private Sub GetExeNames()
Dim hSnapShot As Long, Result As Long
Dim aa As String, bb As String
Dim Process As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = 0 Then Exit Sub
Process.dwSize = Len(Process)
Result = ProcessFirst(hSnapShot, Process)
Do While Result <> 0
aa = Process.szExeFile
aa = Left$(aa, InStr(aa, Chr$(0)) - 1)
If LCase(aa) = "notepad.exe" Then
MsgBox "发现 记事本 程序在运行"
End
End If
Result = ProcessNext(hSnapShot, Process)
Loop
Call CloseHandle(hSnapShot)
End Sub
Private Sub Form_Load()
Me.Show
Do
DoEvents
Call GetExeNames
Loop
End Sub

您所在位置:




