我有 ac# 应用程序需要以管理员身份做一些事情(一些安装工作),然后它需要以非管理员身份运行另一个进程。我以前没有对 UAC 做过任何事情,但我认为一定有办法做到这一点,对吧?
这也需要自动化,因此假设 c# 应用程序是使用管理员凭据启动的。
基本上,该程序将需要执行以下操作:
// MUST run this process as admin
Process adminInstall = new Process();
adminInstall.StartInfo.FileName = "install.bat";
adminInstall.Start();
adminInstall.WaitForExit();
// CANNOT run this process as admin
Process nonAdminProcess = new Process();
nonAdminProcess.StartInfo.FileName = "runner.cmd";
nonAdminProcess.StartInfo.UseShellExecute = false;
nonAdminProcess.StartInfo.RedirectStandardOutput = true;
nonAdminProcess.OutputDataReceived += new DataReceivedEventHandler(myHandler);
nonAdminProcess.Start();
nonAdminProcess.BeginOutputReadLine();
nonAdminProcess.WaitForExit();