How can I run IE with different users and specify a url?

对着背影说爱祢 提交于 2019-12-24 21:30:04

问题


I'm trying to create a console application to replace a batch file. The batch file prompted for a user and ran the following code...

RUNAS /user:USA\%usr% "C:\Program Files\Internet Explorer\iexplore.exe %ServerPath%/%AppName%"

How can I translate this to C# code? I'm basically using the code below. I declare a User Name and a Path, but it always launches IE with my windows login. Am I using Verb incorrectly? Do I need to include a password, and if so, how?

string sPath = ServerPath
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe");
startInfo.Verb = @"runas /user:USA\" + sUser;
startInfo.Arguments = sPath;
startInfo.UseShellExecute = false;
Process.Start(startInfo);

回答1:


function SecureString MakeSecureString(string text)
{
  SecureString secure = new SecureString();
  foreach (char c in text)
  {
    secure.AppendChar(c);
  }

  return secure;
}

function void RunAs(string path, string username, string password)
{
  ProcessStartInfo myProcess = new ProcessStartInfo(path);
  myProcess.UserName = username;
  myProcess.Password = MakeSecureString(password);
  myProcess.UseShellExecute = false;
  Process.Start(myProcess);
}

RunAs(APPLICATION, USERNAME, PASSWORD);

Props to fraser chapman's blog



来源:https://stackoverflow.com/questions/4495596/how-can-i-run-ie-with-different-users-and-specify-a-url

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