程序(c#)运行提升,仍然无法访问某些文件
我的代码正在提升运行,但没有任何东西可以看到/执行 c:\windows\system32\rstrui.exe(系统还原点 UI)。
我仔细检查以确保代码确实在提升运行(确实如此),并且我已经使用 File.Exist() 和 Directory.GetFiles() 以及 System.Diagnostics.Process.Start(); 进行了测试;返回的内容是未找到文件。
该程序确实存在,我真的可以运行它,我可以将路径复制/粘贴到DOS并列出它,执行它(没有隐藏空格等)。
有什么想法吗?
解决方案:
蒂姆(如下)给了我解决方案,而不是引用 c:\windows\system32 引用 c:\windows\sysnative。 “sysnative”被重定向,或者,嗯,没有。我对 x64 重定向的东西仍然有点困惑。重点是,以下工作:
Environment.GetEnvironmentVariable("windir") + @"\sysnative"
谢谢蒂姆!
My code is running elevated but nothing can see/execute c:\windows\system32\rstrui.exe (System Restore Point UI).
I double checked to make sure the code really was running elevated (it is), and I've tested with File.Exist() and Directory.GetFiles() and System.Diagnostics.Process.Start(); file not found is what is returned.
The program is really there, I can really run it, I can copy/paste the path to DOS and list it, execute it (no hidden spaces, etc.).
Any ideas?
THE SOLUTION:
Tim (below) gave me the solution, instead of referencing c:\windows\system32 reference c:\windows\sysnative. The "sysnative" gets redirected, or, well, doesn't. I'm still a bit confused about x64 redirection stuff. The point is, the following works:
Environment.GetEnvironmentVariable("windir") + @"\sysnative"
Thanks Tim!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我猜猜...您在 64 位 Windows 安装上作为 x86 应用程序运行吗?
我不确定原因,但是 此线程提供了一些信息。
如果您针对本机 64 位(或我认为的任何 CPU)而不是 x86 编译它,它会正确找到该文件。
其原因是 64 位操作系统中在 WOW64 下运行的应用程序上发生的系统文件夹重定向。您可以在此处了解更多相关信息。该帖子中有一个特别相关的部分是讨论如何绕过它:
我无法让
%windir%\Sysnative
想法发挥作用,但我希望它对您有用,或者您可以实现启用/禁用重定向。Let me guess... you're running as an x86 application on a 64 bit installation of Windows?
I'm not sure of the reason, but this thread provides some information.
If you compile it for native 64 bit (or Any CPU I suppose) instead of x86, it'll find the file properly.
The reason for this is the System Folder Redirection that's going on in 64bit OS's on applications that are running under WOW64. You can read more about it here. One particularly relevant chunk of that post is talking about how to get around it:
I was unable to get the
%windir%\Sysnative
idea working, but I'm hopeful that either that works for you or you can implement the enabling/disabling of redirection.