UACポップアップを防ぐために、C#cmd.exe
からの引数を使用して管理者として実行したいと考えています。これは、自動インストール プロセスとして使用するために必要です。渡すコマンドは、サイレント インストール用のインストール ファイル (.exe) へのパスです。/q
このコードを実行すると、CMD ポップアップが表示されますが、何も実行されていないかのように実行されます。
public static string ExecuteCommandAsAdmin(string command)
{
ProcessStartInfo procStartInfo = new ProcessStartInfo()
{
RedirectStandardError = true,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
FileName = "runas.exe",
Arguments = "/user:Administrator cmd /K " + command
};
using (Process proc = new Process())
{
proc.StartInfo = procStartInfo;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
if (string.IsNullOrEmpty(output))
output = proc.StandardError.ReadToEnd();
return output;
}
}