如何获得某一个进程的句柄?譬如目前系统里有一个pcxit.exe进程,如何得到它的句柄。

liangshutao 2004-08-12 09:35:58
如何获得某一个进程的句柄?譬如目前系统里有一个pcxit.exe进程,如何得到它的句柄。
...全文
86 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainstormmaster 2004-08-12
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3246/3246375.xml?temp=.5178491
http://community.csdn.net/Expert/topic/3241/3241643.xml?temp=.6134302
danielinbiti 2004-08-12
  • 打赏
  • 举报
回复
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
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 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 Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)
Private Sub Form_Load()
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
Dim str As String
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
ret = Process32First(hSnapShot, uProcess)
Me.AutoRedraw = True
Do While ret
str = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0))
If UCase(str) = UCase("pcxit.exe") Then
Debug.Print CStr(uProcess.th32ProcessID)
Exit Do
End If
ret = Process32Next(hSnapShot, uProcess)
Loop
CloseHandle hSnapShot
End Sub

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧