【问题标题】:Is it possible to require user rights when opening second form ,when application run as administrator?当应用程序以管理员身份运行时,打开第二个表单时是否可以要求用户权限?
【发布时间】:2020-08-24 05:54:37
【问题描述】:

我知道您可以创建一个清单文件来指定整个应用程序的访问级别管理员。但是是否可以只对特定形式要求它?

【问题讨论】:

    标签: c# .net wpf winforms wpf-controls


    【解决方案1】:

    不,这是不可能的。

    您可以做什么:让您的流程在没有提升的情况下运行。 当您发现需要提升但您的进程没有运行提升时,请使用“runas”动词重新启动进程 (Process.Start),也许还有一些命令行选项,您可以在新启动的进程中评估以立即打开表单。

    if (!RunningElevated())
    {
        // restart as elevated process
        ProcessStartInfo psi = new ProcessStartInfo
        {
            UseShellExecute = true,
            Verb = "runas",
            WorkingDirectory = Environment.CurrentDirectory,
            FileName = Assembly.GetExecutingAssembly().Location,
            Argument = "--open MyForm" // has to be evaluated on the startup code
        };
        var process = Process.Start(psi);
        if (process != null)
            Application.Current.Shutdown(0); // this is for WPF
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2020-02-10
      • 2023-03-07
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多