この方法では、過去に私のために働いていた:私はここで直接あなたのバッチファイルでコマンドを実行しているんだけど、もちろんあなたも、バッチファイル自体を実行することができます
string exe = @"C:\Project\Test\InstallUtil.exe";
string args = @"C:\Project\Test\ROServerService\Server\bin\Debug\myservices.exe"
var psi = new ProcessStartInfo();
psi.CreateNoWindow = true; //This hides the dos-style black window that the command prompt usually shows
psi.FileName = @"cmd.exe";
psi.Verb = "runas"; //this is what actually runs the command as administrator
psi.Arguments = "/C " + exe + " " + args;
try {
var process = new Process();
process.StartInfo = psi;
process.Start();
process.WaitForExit();
}
catch (Exception){
//If you are here the user clicked declined to grant admin privileges (or he's not administrator)
}
注:
を
string bat = @"C:\path\to\your\batch\file.bat";
var psi = new ProcessStartInfo();
psi.CreateNoWindow = true; //This hides the dos-style black window that the command prompt usually shows
psi.FileName = @"cmd.exe";
psi.Verb = "runas"; //this is what actually runs the command as administrator
psi.Arguments = "/C " + bat;
これを管理者モードでクライアントのマシンでどのように実行できますか? –
@EnigmaticMind:私はあなたの質問を理解していない...コードはすでに管理モードでコマンドを実行します。あなたの問題は何ですか? –
上記のコードをWebアプリケーションに入れました。バットファイルのパスに私はサーバIP(クライアントIP)を与えました。+ pathそれは動作していませんでした。つまり、コードがWebアプリケーションのために機能するかどうかということでした。 –