[英]Avoid UAC prompts when calling another process using C#
I'm developing an iventory software for my company that demands administrative rights (WMI calls, registry access, etc.).我正在为我的公司开发一个需要管理权限(WMI 调用、注册表访问等)的库存软件。 For convenience I do no want the UAC to prompt the user for clearance to execute the app (yes, I must force the app to run even if the the user doesn't want), and I can't disable the UAC via GPO (would be perfect but a pain in the ass).为方便起见,我不希望 UAC 提示用户许可以执行应用程序(是的,即使用户不想要,我也必须强制应用程序运行),并且我无法通过 GPO 禁用 UAC(将是完美的,但会很痛苦)。 I first tried to pass an AD administrative account credentials to the inventory software using another process (Processinfo on C#) but the UAC prompts remained.我首先尝试使用另一个进程(C# 上的 Processinfo)将 AD 管理帐户凭据传递给库存软件,但 UAC 提示仍然存在。 After a few research I discovered that if use the local Administrator credential it wouldn't give me any annoying prompt but since my company's environment is a mess, there are many stations with different credentials other than the standardized.经过一些研究,我发现如果使用本地管理员凭据,它不会给我任何烦人的提示,但是由于我公司的环境一团糟,除了标准化之外,还有许多站点具有不同的凭据。 Does anyone have any idea of how I could do this?有谁知道我如何做到这一点? (Using .net C#). (使用 .net C#)。
I have accomplished this using the Task Scheduler Managed Wrapper .我已经使用Task Scheduler Managed Wrapper完成了这项工作。 Be sure that you provide the local administrator group credential in setting up the task.确保在设置任务时提供本地管理员组凭据。 Here's how I do it in my code:这是我在代码中的做法:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.