发布网友
共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