0

我正在尝试创建一个控制台应用程序来替换批处理文件。批处理文件提示输入用户并运行以下代码...

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

如何将其转换为 C# 代码?我基本上使用下面的代码。我声明了一个用户名和一个路径,但它总是在我的 Windows 登录时启动 IE。我是否错误地使用了动词?我是否需要包含密码,如果需要,如何输入?

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);
4

1 回答 1

3
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);

弗雷泽查普曼博客的道具

于 2010-12-21T01:37:30.880 回答