拒绝访问而得到处理路径 [英] Access denied while getting process path

查看:1153
本文介绍了拒绝访问而得到处理路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过PID获取进程的路径,但我发现Win32Exception(访问ID被拒绝)。

I am trying to get process path by pid but I'm getting Win32Exception (access id denied).

在code是这样的:

string path = Process.GetProcessById(pid).MainModule.FileName

我已经使用调用OpenProcess与GetModuleFileNameEx尝试,但调用OpenProcess将返回0。我甚至试图根据的 C# - 如何启用SeDebugPrivilege ,但它并没有帮助

以上code适用于大多数的过程,但会引发错误SynTPHelper.exe(Synaptics的指点设备助手)应用程序是相同的用户名作为我的code下运行。在这两方面,我的应用程序和进程的64位运行。

The above code works for most of the processes but throws error for SynTPHelper.exe (Synaptics Pointing Device Helper) The application is running under the same username as my code. Both, my application and the process run in 64 bit.

是否有可能检索路径的没有运行我的应用程序作为管理员?

Is it possible to retrieve the path without running my application as an administrator?

修改

任务管理器是能够打开文件位置即使我没有运行它作为一个管理员。

Task Manager is able to 'open file location' even though I'm not running it as an administrator.

推荐答案

最后,我设法解决这个问题。事实证明没有在Vista和上面获取过程中的路径和新的进程访问(PROCESS_QUERY_LIMITED_INFORMATION)新功能:

Finally I managed to solve it. As it turned out there is new function in Vista and above for getting process path and new process access (PROCESS_QUERY_LIMITED_INFORMATION):

<一个href=\"http://msdn.microsoft.com/en-us/library/ms684919%28VS.85%29.aspx\">QueryFullProcessImageName

下面是code,从非提升过程的工作:

Here is the code that works from non-elevated process:

    private static string GetExecutablePathAboveVista(UIntPtr dwProcessId)
    {
        StringBuilder buffer = new StringBuilder(1024);
        IntPtr hprocess = OpenProcess(ProcessAccessFlags.PROCESS_QUERY_LIMITED_INFORMATION, false, dwProcessId);
        if (hprocess != IntPtr.Zero)
        {
            try
            {
                int size = buffer.Capacity;
                if (QueryFullProcessImageName(hprocess, 0, buff, out size))
                {
                    return buffer.ToString();
                }
            }
            finally
            {
                CloseHandle(hprocess);
            }
        }
        return string.Empty;
    }

这篇关于拒绝访问而得到处理路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆