非常に興味深い問題があります。
「runas」動詞で Process.Start を使用して、プロセスを管理者として実行します。
string currentstatus;
ProcessStartInfo startInfo = new ProcessStartInfo();
Process myprocess = new Process();
try
{
startInfo.FileName = "cmd"; //
startInfo.Verb = "runas";
startInfo.Arguments = "/env /user:" + "Administrator" + " cmd";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false; //'required to redirect
startInfo.CreateNoWindow = true; // '<---- creates no window, obviously
myprocess.StartInfo = startInfo; //
myprocess.Start(); //
System.IO.StreamReader SR;
System.IO.StreamWriter SW;
Thread.Sleep(200);
SR = myprocess.StandardOutput;
SW = myprocess.StandardInput;
SW.WriteLine(commandexecuted); // 'the command you wish to run.....
SW.WriteLine("exit"); // 'exits command prompt window
Thread.Sleep(200);
currentstatus = SR.ReadToEnd();
SW.Close();
SR.Close();
}
catch (Exception e)
{ }
コマンドを実行したと言われているものは次のように与えられます
exp *****/******@!!!!!!! owner =!!!!!!!! file =D:/SS.dmp
今私の問題は
1)cmd.exeを右クリックして上記のクエリを手動で実行し、「管理者として実行」を選択すると正常に動作しますが、それがないとエラーがスローされます
2)コードを介してそのプロセスを実行する必要があります。
どこで間違えたのかわからない?
これはオラクルダンプを取る唯一の方法ですか、それとも他の方法があるのでしょうか?
貴重なご意見・ご感想をお待ちしております.....
更新 1)
私もこのコードを使用して、現在のユーザーが管理者であるかどうかを確認します
private static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
現在のユーザーは管理者のみであるため、返されました。
上記の問題に対する任意の提案!