Vb2008 如何获取进程PID 10
PublicFunctionFindPID(ByValstrGameNameAsString)AsBooleanDimpe32AsPROCESSENTRY32DimhSn...
Public Function FindPID(ByVal strGameNameAs String) As Boolean
Dim pe32 As PROCESSENTRY32
Dim hSnapshot As Integer
Dim bProcFound As Boolean
Dim bFoundGame As Boolean
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0)
pe32.dwSize = Len(pe32)
bProcFound = Process32First(hSnapshot,pe32)
Do While bProcFound
If Right(LCase(Left(pe32.szExeFile,
InStr(1, pe32.szExeFile, Chr(0)) - 1)), Len(strGameName)) = LCase(strGameName)
Then
dwProcId = pe32.th32ProcessID
bFoundGame = True
End If
bProcFound = Process32Next(hSnapshot,pe32)
Loop
CloseHandle(hSnapshot)
dwHandle = OpenProcess(&H1F0FFF,False, dwProcId)
FindGame = bFoundGame
End Function
之前用这个获取程序的PID,可是变成了2008就好像不行
有想过用Process.GetProcessesByName不过不太会用,因为出来的
好像不是我所想要的值(dwProcId),如果有人可以用这个得出PID的数值出来也可以 展开
Dim pe32 As PROCESSENTRY32
Dim hSnapshot As Integer
Dim bProcFound As Boolean
Dim bFoundGame As Boolean
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0)
pe32.dwSize = Len(pe32)
bProcFound = Process32First(hSnapshot,pe32)
Do While bProcFound
If Right(LCase(Left(pe32.szExeFile,
InStr(1, pe32.szExeFile, Chr(0)) - 1)), Len(strGameName)) = LCase(strGameName)
Then
dwProcId = pe32.th32ProcessID
bFoundGame = True
End If
bProcFound = Process32Next(hSnapshot,pe32)
Loop
CloseHandle(hSnapshot)
dwHandle = OpenProcess(&H1F0FFF,False, dwProcId)
FindGame = bFoundGame
End Function
之前用这个获取程序的PID,可是变成了2008就好像不行
有想过用Process.GetProcessesByName不过不太会用,因为出来的
好像不是我所想要的值(dwProcId),如果有人可以用这个得出PID的数值出来也可以 展开
1个回答
展开全部
Public Function ProcessPidOnly(ByVal ProcessName As String) As String
Dim myProcess As Process() = Process.GetProcessesByName(ProcessName)
Dim pid As String = ""
If myProcess.Length - 1 = 0 Then
pid = myProcess(0).Id
Else
For i As Short = 0 To myProcess.Length - 1
pid = pid & myProcess(i).Id & ";"
Next
End If
Return pid
End Function
Dim myProcess As Process() = Process.GetProcessesByName(ProcessName)
Dim pid As String = ""
If myProcess.Length - 1 = 0 Then
pid = myProcess(0).Id
Else
For i As Short = 0 To myProcess.Length - 1
pid = pid & myProcess(i).Id & ";"
Next
End If
Return pid
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询