Windows UAC - 如何处理用户取消 [英] Windows UAC - How to Handle the User Cancelling

查看:28
本文介绍了Windows UAC - 如何处理用户取消的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要生成一个具有提升权限的进程,这会导致为用户弹出 UAC 提示:

I need to spawn a process with elevated privileges which would cause a UAC prompt to pop up for the user:

using (process = new Process())
{
    process.StartInfo.FileName = fileName;
    process.StartInfo.Arguments = string.Join(" ", arg1, arg2, arg3);
    process.StartInfo.Verb = "runas";
    process.Start();
}

我遇到的问题是,如果用户在 UAC 提示中选择否",进程对象将抛出一个异常,指出操作已被用户取消".如果用户选择否,则父进程应该照常继续(生成的进程是完全可选的).除了捕获异常而什么都不做之外,还有没有更好的方法来处理这种情况?

The problem that I'm having is that if the user selects 'no' in the UAC prompt, the process object will throw an exception stating that 'The operation was canceled by the user.' If the user selects no, then the parent process should just continue as normal (the spawned process is completely optional). Is there a better way of handling this scenario other than just catching the exception and doing nothing?

推荐答案

除了捕获异常而什么都不做之外,您还想做什么?这是我唯一能想到的.

What else would you want to do instead of catching the exception and doing nothing? That is the only thing that I can think about.

这篇关于Windows UAC - 如何处理用户取消的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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