vb如何通过进程标识符找到的pid关闭程序
用FindWindow和GetWindowThreadProcessId可以找到这个程序的pid找到了只有如何关闭这个pid呢?因为pid是个变量,用taskkill/p...
用FindWindow和GetWindowThreadProcessId可以找到这个程序的pid
找到了只有如何关闭这个pid呢?
因为pid是个变量,用taskkill /pid 这个后面的pid一定要是变量才行
或者有其他的别的什么好办法吗》? 展开
找到了只有如何关闭这个pid呢?
因为pid是个变量,用taskkill /pid 这个后面的pid一定要是变量才行
或者有其他的别的什么好办法吗》? 展开
1个回答
展开全部
这个方法也挺好。我用记事本程序为例,你先打开记事本程序,添加如下代码,单击窗体即可。
==============
Option Explicit
Dim h As OLE_HANDLE, Pid As OLE_HANDLE
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Form_Click()
h = FindWindow("Notepad", vbNullString)
GetWindowThreadProcessId h, Pid
Shell "taskkill /PID " & Pid
End Sub
==============
Option Explicit
Dim h As OLE_HANDLE, Pid As OLE_HANDLE
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Form_Click()
h = FindWindow("Notepad", vbNullString)
GetWindowThreadProcessId h, Pid
Shell "taskkill /PID " & Pid
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询