如何使用不同的用户运行 IE 并指定 url?

发布于 2024-10-08 05:53:10 字数 558 浏览 0 评论 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);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨与橙与城 2024-10-15 05:53:10
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);

支持fraser chapman 的博客

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文