Get Executable Path of Window by Handle - Access Denied

雨燕双飞 提交于 2019-12-08 05:27:05

问题


I am trying to get Executable Path of Window by Handle.
I am using the following code to achieve:

[DllImport("user32.dll")]
private static extern int GetWindowThreadProcessId(IntPtr handle, out uint processId);

public string GetFilePath(IntPtr hwnd)
{
    try
    {
        uint pid = 0;
        GetWindowThreadProcessId(hwnd, out pid);
        Process proc = Process.GetProcessById((int)pid); //Gets the process by ID.
        return proc.MainModule.FileName.ToString();   //Returns the path.
    }
    catch (Exception ex)
    {
        return ex.ToString();
    }
}

and it works fine, except for some applications (such as TeamSpeak 3 64bit [if it matters]).

How can I overcome the Access Denied problem programmaticly?

I tried to use the following aswell but same problem:
Get a executable path from a window handle?
Access denied while getting process path
How to Get Elevated Process Path in .NET

来源:https://stackoverflow.com/questions/20583644/get-executable-path-of-window-by-handle-access-denied

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!