【问题标题】:Avoid UAC prompts when calling another process using C#使用 C# 调用另一个进程时避免 UAC 提示
【发布时间】:2015-10-26 22:40:05
【问题描述】:

我正在为我的公司开发一个需要管理权限(WMI 调用、注册表访问等)的 iventory 软件。为方便起见,我不希望 UAC 提示用户执行应用程序的许可(是的,即使用户不想要,我也必须强制应用程序运行),并且我不能通过 GPO 禁用 UAC(将是完美的,但很痛苦)。我首先尝试使用另一个进程(C# 上的 Processinfo)将 AD 管理帐户凭据传递给库存软件,但 UAC 提示仍然存在。经过一些研究,我发现如果使用本地管理员凭据,它不会给我任何烦人的提示,但由于我公司的环境一团糟,除了标准化之外,还有许多具有不同凭据的站点。有谁知道我该怎么做? (使用 .net C#)。

【问题讨论】:

  • 改用服务或计划任务。
  • 想象一下你找到了绕过 UAC 的方法。现在将其外推到所有不断针对 Windows 的病毒/恶意软件编写者。它不是为了给您带来不便,而是为了保护用户。
  • “是的,即使用户不想要,我也必须强制应用运行”——我的意思是,这就是 UAC 存在的全部原因。
  • 您的处理方法似乎不切实际。尝试融入系统而不是颠覆它。

标签: c# .net uac impersonation


【解决方案1】:

我已经使用Task Scheduler Managed Wrapper 完成了这项工作。确保在设置任务时提供本地管理员组凭据。以下是我在代码中的做法:

        using (TaskService ts = new TaskService())
        {
            try
            {
                //Create a new task definition and assign properties
                TaskDefinition td = ts.NewTask();
                td.Principal.RunLevel = TaskRunLevel.Highest;
                td.RegistrationInfo.Description = "Paulos Task";
                td.Triggers.Add(new TimeTrigger() { StartBoundary = Convert.ToDateTime("01-01-2003 00:00:01") });

                // Create an action that will launch PauloApp whenever the trigger fires
                td.Actions.Add(new ExecAction("PauloApp.exe", "", Environment.ExpandEnvironmentVariables(@"%ProgramFiles%\Paulo")));

                td.Settings.DisallowStartIfOnBatteries = false;
                td.Settings.StopIfGoingOnBatteries = false;

                ts.RootFolder.RegisterTaskDefinition("PaulosTask", td,
                   TaskCreation.CreateOrUpdate, "Administrators", null,
                   TaskLogonType.Group);

                // Register the task in the root folder
                Microsoft.Win32.TaskScheduler.Task t = ts.FindTask("PaulosTask");
                if (t != null)
                    t.Run();
                else
                    //could not find PaulosTask
            }//end try
            catch (Exception e)
            {
            }
        }//end using

【讨论】:

  • 我需要提供本地凭据还是可以使用具有管理权限的域凭据?
  • 我只使用本地管理员组对其进行了测试。我想您也可以使用域凭据,但如果您这样做了,我认为您部署应用程序的每个系统都需要将您的域 Windows 用户名作为本地系统上的 Windows 管理员存在?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-26
  • 2014-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多