要求Windows Vista的UAC提升,如果路径保护?路径、Windows、Vista、UAC

2023-09-02 21:08:09 作者:风月本无界

有关我的C#应用​​程序,我不想总是提示抬高在应用程序启动,但如果他们选择的是UAC保护然后我需要请求提升输出路径。

For my C# app, I don't want to always prompt for elevation on application start, but if they choose an output path that is UAC protected then I need to request elevation.

那么,我该如何检查,如果路径是UAC保护,那我怎么要求抬高中期执行?

So, how do I check if a path is UAC protected and then how do I request elevation mid-execution?

推荐答案

要检测,如果他们无法执行的操作是尝试它,并抓住 UnauthorizedAccessException 。

The best way to detect if they are unable to perform an action is to attempt it and catch the UnauthorizedAccessException.

然而,由于@ DannySmurf correctly指出你只能提高一个COM对象或独立的进程。

However as @DannySmurf correctly points out you can only elevate a COM object or separate process.

目前距离Windows SDK的跨技术样本称为 UAC演示一个演示应用程序。该示范应用表明执行行动,提升过程的方法。它还演示了如何找出如果用户是当前管理员。

There is a demonstration application within the Windows SDK Cross Technology Samples called UAC Demo. This demonstration application shows a method of executing actions with an elevated process. It also demonstrates how to find out if a user is currently an administrator.