通常(在Windows 7中),安装程序将要求修改系统的权限。作为管理员,我可以在不提供密码的情况下授予授权。
我正在尝试弄清楚如何从作为AN管理员但不是“管理员”帐户的用户运行的C#代码中执行管理员操作(重新启动IIS)。
答案 0 :(得分:3)
要以提升方式运行流程,您可以使用 runas 动词。
Process elevated = new Process();
elevated.StartInfo.Verb = "runas";
elevated.StartInfo.FileName = "Whatever.exe";
elevated.Start();
要重新启动IIS(如前所述),请使用iisreset。
希望你觉得这很有用。
答案 1 :(得分:2)
尝试从C#
执行IISReset
命令
http://technet.microsoft.com/en-us/library/cc758159(WS.10).aspx
iisreset /noforce
使用ProcessStart
System.Diagnostics.Process.Start(@"C:\Windows\System32\iisreset.exe");
如果您正在使用AD身份验证而且您是管理员,那么该工作
答案 2 :(得分:2)
对于仍在寻找此问题的人,这里是我用来帮助我解决这个问题的代码。
private static void DoIISReset()
{
Process iisReset = new Process();
iisReset.StartInfo.FileName = "iisreset.exe";
iisReset.StartInfo.RedirectStandardOutput = true;
iisReset.StartInfo.UseShellExecute = false;
iisReset.Start();
iisReset.WaitForExit();
}
希望这有帮助!
答案 3 :(得分:2)
System.Diagnostics.Process.Start(@"C:\Windows\System32\iisreset.exe");
此代码对您有帮助,但您可以获得拒绝访问权限。
因为你没有得到拒绝访问;
1)右键单击Project 2)添加新的İtem 3)添加应用程序清单文件 enter image description here
4)更改此代码
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
这个
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
答案 4 :(得分:0)
有两种方法可以执行此操作,但是您都需要以管理身份运行VS。
此代码将在空白的 cmd 中提示一段时间,并将自动关闭窗口。
Process iisReset = new Process();
iisReset.StartInfo.FileName = "iisreset.exe";
iisReset.StartInfo.RedirectStandardOutput = true;
iisReset.StartInfo.UseShellExecute = false;
iisReset.Start();
iisReset.WaitForExit();
此代码还将重新启动IIS,并且只需进行少量处理即可提示 CMD 。
Process.Start(@"C:\WINDOWS\system32\iisreset.exe", "/noforce");
答案 5 :(得分:-1)
以下是关于如何在power shell中完成此操作的链接 http://www.computerperformance.co.uk/powershell/powershell_service_start.htm
另一种可能性是使用WMI http://www.motobit.com/tips/detpg_vbs-wmi-restart-service/
这是另一种直接的方式# http://www.csharp-examples.net/restart-windows-service/
我希望这有帮助......