API 取进程名,错误代码 299 怎么解决
程序代码: Dim ModuleMsg As API声明.MODULEENTRY32, hSnapShot As Long
hSnapShot = API声明.CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID) '建立进程快照
If hSnapShot > 0 Then
API声明.CopyMemory_Long ModuleMsg.dwSize, Len(ModuleMsg), 4
If API声明.Module32First(hSnapShot, ModuleMsg) > 0 Then '获取模块信息
With ModuleMsg
GetPoocessOfByPId = .szModule
End With
End If
End If
Debug.Print API声明.GetLastError
API声明.CloseHandle hSnapShot
程序代码:Public Function GetProcessPathByProcessID(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 = EnumProcessModules(hProcess, szBuf(1), 250, cbNeeded)
If Ret <> 0 Then
Debug.Print GetLastError, "e"
szPathName = Space(260)
nSize = 500
Ret = GetModuleFileNameExA(hProcess, szBuf(1), szPathName, nSize)
GetProcessPathByProcessID = Left(szPathName, Ret)
End If
End If
Ret = CloseHandle(hProcess)
If GetProcessPathByProcessID = "" Then
Debug.Print GetLastError
GetProcessPathByProcessID = "SYSTEM"
End If
Exit Function
Z:
End Function我用了两种不同的办法,取进程名,都取不到,而且都是返回 299 ,求解决,我百度不到








