vb 如何获取进程PID
答案:4 悬赏:30 手机版
解决时间 2021-02-10 00:35
- 提问者网友:嘚啵嘚啵
- 2021-02-09 11:30
vb6.0 编写一个程序,功能为:根据进程名字而获取其PID。希望能详细标识注解,切勿复制网上不可用的代码。谢谢!
最佳答案
- 五星知识达人网友:掌灯师
- 2021-02-09 12:14
要用bai到2个API函数
1.Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long 从窗口du句并获取进程zhidaoPID
2.Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 查找窗口句柄
pw = FindWindow(vbNullString, "连连看专 v4.1")‘'查找连连看把找到的结果存在属PW是保存窗口句柄GetWindowThreadProcessId pw, pid '从窗口句柄获取进程ID,PID是保存进程ID
1.Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long 从窗口du句并获取进程zhidaoPID
2.Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 查找窗口句柄
pw = FindWindow(vbNullString, "连连看专 v4.1")‘'查找连连看把找到的结果存在属PW是保存窗口句柄GetWindowThreadProcessId pw, pid '从窗口句柄获取进程ID,PID是保存进程ID
全部回答
- 1楼网友:由着我着迷
- 2021-02-09 15:00
tasklist>123.txt
然后把文件内容读出来,简单处理一下。。。
- 2楼网友:玩世
- 2021-02-09 14:22
窗体上添加一个 text 一个按钮command 只需在text中输入进程名 explorer.exe 单击一下按钮 就可以 获取该进程的pid 显示在text1上,要用到三个api:
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 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
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
dim pname as string
dim a as string
private sub command1_click()
a = trim(lcase(text1))
dim my as processentry32
dim l as long
dim l1 as long
dim flag as boolean
dim mname as string
dim i as integer
l = createtoolhelp32snapshot(th32cs_snapprocess, 0)
if l then
my.dwsize = 1060
end if
if (process32first(l, my)) then '遍历第一个进程
do
i = instr(1, my.szexefile, chr(0)) '返回chr(0)在各个进程中出现的位置
mname = lcase(left(my.szexefile, i - 1)) '返回小写的(返回i-1的前n个字符,即正确的名称)
if mname = a then
pid = my.th32processid
text1 = text1 & "的pid是 " & "---" & pid
end if
loop until (process32next(l, my) < 1)
end if
end sub
- 3楼网友:低血压的长颈鹿
- 2021-02-09 13:16
一、把下面代码放入一个模块中32313133353236313431303231363533e4b893e5b19e31333332633030
Option Explicit Public Declare Function ZwQueryInformationProcess _
Lib "NTDLL.DLL" (ByVal ProcessHandle As Long, _ ByVal ProcessInformationClass As PROCESSINFOCLASS, _ ByVal ProcessInformation As Long, _ ByVal ProcessInformationLength As Long, _ ByRef ReturnLength As Long) As Long
Public Enum PROCESSINFOCLASS ProcessBasicInformation ProcessQuotaLimits
ProcessIoCounters ProcessVmCounters ProcessTimes ProcessBasePriority ProcessRaisePriority ProcessDebugPort ProcessExceptionPort ProcessAccessToken ProcessLdtInformation ProcessLdtSize ProcessDefaultHardErrorMode
ProcessIoPortHandlers '// Note: this is kernel mode only
ProcessPooledUsageAndLimits ProcessWorkingSetWatch
ProcessUserModeIOPL
ProcessEnableAlignmentFaultFixup
ProcessPriorityClass
ProcessWx86Information
ProcessHandleCount
ProcessAffinityMask
ProcessPriorityBoost
ProcessDeviceMap
ProcessSessionInformation
ProcessForegroundInformation
ProcessWow64Information
ProcessImageFileName
ProcessLUIDDeviceMapsEnabled
ProcessBreakOnTermination
ProcessDebugObjectHandle
ProcessDebugFlags
ProcessHandleTracing
ProcessIoPriority
ProcessExecuteFlags
ProcessResourceManagement
ProcessCookie
ProcessImageInformation
MaxProcessInfoClass '// MaxProcessInfoClass should always be the last enum
End Enum
Public Type PROCESS_BASIC_INFORMATION
ExitStatus As Long 'NTSTATUS
PebBaseAddress As Long 'PPEB
AffinityMask As Long 'ULONG_PTR
BasePriority As Long 'KPRIORITY
UniqueProcessId As Long 'ULONG_PTR
InheritedFromUniqueProcessId As Long 'ULONG_PTR
End Type
Private Function GetProcessId(ByVal hProcess As Long) As Long
Dim st As Long
Dim pbi As PROCESS_BASIC_INFORMATION: pbi = GetProcessBasicInfo(hProcess)
GetProcessId = pbi.UniqueProcessId
End Function
Private Function GetProcessBasicInfo(ByVal hProcess As Long) As PROCESS_BASIC_INFORMATION
Dim st As Long
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯