永发信息网

vb 如何获取进程PID

答案:4  悬赏:30  手机版
解决时间 2021-02-10 00:35
vb6.0 编写一个程序,功能为:根据进程名字而获取其PID。希望能详细标识注解,切勿复制网上不可用的代码。谢谢!
最佳答案
要用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
全部回答
tasklist>123.txt 然后把文件内容读出来,简单处理一下。。。
窗体上添加一个 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
一、把下面代码放入一个模块中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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
谁有腾讯qq内部人员的qq号
童颜丽人地址有知道的么?有点事想过去
如果男女双方在经济方面差距挺大的(女不如男
【秦谜】是几个关于历史的谜语1.《孙子兵法》
紫韵时尚品牌服饰地址在什么地方,想过去办事
逸姿依美容(王府井百货店)地址在什么地方,我
incanto amity什么意思
美信嘉百货地址在哪,我要去那里办事
恶魔少爷别吻我现在为什么看不了了?
【敬佩】填上合适的词语敬佩得怎么样
苹果6splus黑屏只有链接充电器才能开机,经常
广西医科大学的专科在广西好吗??
时尚伊人地址有知道的么?有点事想过去
大坝上我想知道这个在什么地方
实况足球2018 限定版 有巴塞罗那特典吗
推荐资讯
广东省民办教师超生怎样处罚
儿子得了肾病综合征一定要用环磷酰胺吗?副作
在总需求不足,失业率超过自然失业率,出现通
韩国密澜隐形发地址好找么,我有些事要过去
南坨子在什么地方啊,我要过去处理事情
不入耳的耳机怎么戴牢固
宝妈帮我看下我的宝宝有多大2485g是多大宝妈
戴家屋场地址在什么地方,想过去办事
先测0.1mol/L醋酸溶液的PH,然后将其加热至100
文化社区居委会地址在什么地方,想过去办事
大理景点大理本地人有优惠吗
阳光女人专业瘦身美容SPA养生会所(茶局巷店)
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?