帮忙翻译 vb 由进程名获取PID

寻答案:vb从进程名获取PID以下是刚找到类似的代码,求达人解读=============================OptionExplicitPrivateDec... 寻答案:vb 从进程名获取PID

以下是刚找到类似的代码,求达人解读
=============================
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Const WM_CLOSE = &H10
Public Function EndOld(WindowName As String)
Dim app_hWnd As Long
app_hWnd = FindWindow(vbNullString, WindowName)
If app_hWnd <> 0 Then
SendMessage app_hWnd, WM_CLOSE, 0, 0

TerminateProcess app_hWnd, 0
End If
End Function
展开
 我来答
FallenCC
2010-02-03
知道答主
回答量:23
采纳率:0%
帮助的人:25.2万
展开全部
'创建个模块

Option Explicit
'私有的CreateToolhelp32Snapshot
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
'公有的TerminateProcess
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Const TH32CS_SNAPPROCESS = &H2&
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 * 260
End Type
Const PROCESS_TERMINATE = 1

Function 取进程PID(sProcess As String) As Long
Dim lSnapShot As Long
Dim lNextProcess As Long
Dim tPE As PROCESSENTRY32
lSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If lSnapShot <> -1 Then
tPE.dwSize = Len(tPE)
lNextProcess = Process32First(lSnapShot, tPE)
Do While lNextProcess
If LCase$(sProcess) = LCase$(Left(tPE.szExeFile, InStr(1, tPE.szExeFile, Chr(0)) - 1)) Then
Dim lProcess As Long
Dim lExitCode As Long
取进程PID = tPE.th32ProcessID
CloseHandle lProcess
End If
lNextProcess = Process32Next(lSnapShot, tPE)
Loop
CloseHandle (lSnapShot)
End If
End Function

'窗口

Private Sub Form_Load()
Print 取进程PID("qq.exe")

Print 取进程PID(Text1.Text)

end

以前弄的 还保留着 希望帮到你
aspd199
2010-02-03 · TA获得超过906个赞
知道小有建树答主
回答量:865
采纳率:50%
帮助的人:487万
展开全部
同一个进程名,可能会有很多个PID,只需要把PID对应的进程名做比较 符合的列出来就行了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
chenxfsoft
2010-02-03 · TA获得超过1380个赞
知道大有可为答主
回答量:2418
采纳率:0%
帮助的人:1846万
展开全部
EndOld(WindowName )
找到标题为 windowsname 的窗口,如果找到,把这个窗口关了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式