vb關(guān)閉進(jìn)程
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
'API函數(shù)聲明 Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long 'PROCESSENTRY32 類型聲明 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 * 1024 End Type '常數(shù) Const TH32CS_SNAPHEAPLIST = &H1 Const TH32CS_SNAPPROCESS = &H2 Const TH32CS_SNAPTHREAD = &H4 Const TH32CS_SNAPMODULE = &H8 Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Const TH32CS_INHERIT = &H80000000 Dim pid As Long Private Sub Command1_Click() Dim my As PROCESSENTRY32 Dim l As Long Dim l1 As Long Dim mName As String Dim i As Integer Dim mProcID As Long Dim PrcArry As String PrcArry = "cs_app_server.exe" l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then my.dwSize = 1060 If (Process32First(l, my)) Then '遍歷第一個(gè)進(jìn)程 Do i = InStr(1, my.szExeFile, Chr(0)) mName = LCase(Left(my.szExeFile, i - 1)) If UCase(mName) = UCase(PrcArry) Then pid = my.th32ProcessID mProcID = OpenProcess(1&, -1&, pid) TerminateProcess mProcID, 0& End If Loop Until (Process32Next(l, my) < 1) '遍歷所有進(jìn)程知道返回值為False End If l1 = CloseHandle(l) End If End Sub 該文章在 2013/12/26 16:12:45 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |