programmatically run cmd.exe as administrator in vista, C#

跟風遠走 提交于 2019-11-30 20:51:49
Lucas Jones

Try executing the runas command:

...

using System.Diagnostics;

...

string UserName = "user name goes here";
ProcessStartInfo p1 = new ProcessStartInfo();
  p1.FileName = "runas";
  p1.Arguments = String.Format("/env /u:{0} cmd", UserName);
Process.Start(p1);

...

(And I don't think you need an explicit UseShellExecute)

Just Try this, This worked for Me.

...

using System.Diagnostics;

...

ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.UseShellExecute = true;            
  startInfo.Verb = "runas";
  startInfo.Arguments = "/env /user:" + "Administrator" + " cmd";
Process.Start(startInfo);

...

Ashutosh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!