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

fraser chapman のブログの小道具

于 2010-12-21T01:37:30.880 に答える