返回首页
当前位置: 主页 > 网络编程 > .Net实例教程 >

C# runas 功能的实现,C#使用指定管理员权限运行外部程序

时间:2017-07-18 22:54来源:知行网www.zhixing123.cn 编辑:麦田守望者

LauchMontanaBrt(admin,pass, "D:\\Program Files (x86)\\Advanced IP Scanner\\advanced_ip_scanner.exe"); //運行程序

 

 

public static bool LauchMontanaBrt(string inUserName, string inPassWord, string run)
{
try
{
Process MBRTProcess = new Process();
MBRTProcess.StartInfo.UserName = inUserName;
string strPWD = inPassWord;
SecureString password = new SecureString();
foreach (char c in strPWD.ToCharArray())
{
password.AppendChar(c);
}
MBRTProcess.StartInfo.Password = password;
MBRTProcess.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
MBRTProcess.StartInfo.FileName = "xxx.exe";
MBRTProcess.StartInfo.Arguments = "/run /wu";
MBRTProcess.StartInfo.UseShellExecute = false;
MBRTProcess.Start();
return true;
}
catch(Exception error)
{
Console.writeline(error.Message);
return false;
}
}

------分隔线----------------------------
标签(Tag):C#
------分隔线----------------------------
推荐内容
猜你感兴趣