vb 获得进程的路径(已知pid)

发布网友

我来回答

1个回答

热心网友

Private Function GetProcessPath(PID As Long) As String
On Error GoTo Z
Dim cbNeeded As Long
Dim szBuf(1 To 250) As Long
Dim Ret As Long
Dim szPathName As String
Dim nSize As Long
Dim hProcess As Long
hProcess = OpenProcess(&H400 Or &H10, 0, PID) '这才是进程的正确打开方式^-^
If hProcess <> 0 Then
Ret = EnumProcessMoles(hProcess, szBuf(1), 250, cbNeeded)
If Ret <> 0 Then
szPathName = Space(260)
nSize = 500
Ret = GetMoleFileNameExA(hProcess, szBuf(1), szPathName, nSize)
GetProcessPath = Left(szPathName, Ret)
End If
End If
Ret = CloseHandle(hProcess)
If GetProcessPath = "" Then
GetProcessPath = "--"
End If
Exit Function
Z:
End Function

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com