Hello!

I am running the following code to find out the name of a process from a process ID.

However, hProcess is always 0, and Err.LastDLLError is 87.

Code:
Public Function GetExePathFromProcessID(ByVal idProc As Long) As String

    Dim sBuf As String
    Dim sChar As Long, l As Long, hProcess As Long
    hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, idProc)  ' Or PROCESS_VM_READ or would only work if admin!
    If hProcess Then
        sBuf = VBA.String(260, vbNullChar)
        sChar = GetProcessImageFileName(hProcess, sBuf, 260)
        
        Debug.Assert False 'todo
      
        CloseHandle hProcess
    Else
        Dim lErr&
        lErr = Err.LastDLLError
        Debug.Print lErr
    End If
    
End Function
What does this error code mean?

Thank you!