![](/img/trans.png)
[英]Process.Start for system32 applications - The System Cannot Find the File Specified
[英]C# ProcessStartInfo and Process.Start cannot find programs in System32
我正在嘗試在 C# 中使用提升的權限運行 shell 命令。 但是,以下代碼返回:
該系統找不到指定的文件。
string command = System.IO.Path.Combine(Environment.SystemDirectory, "wdsutil.exe");
string args = ""; //Appropriate arguments
ProcessStartInfo psInfo = new ProcessStartInfo(command);
psInfo.Arguments = args;
psInfo.Verb = "runas";
try
{
Process p = Process.Start(psInfo);
p.WaitForExit();
return "Try Done";
}
catch(Exception e)
{
return e.Message;
}
錯誤也存在,沒有 SystemDriectory 前綴。
但是,如果我執行命令C:\\wdsutil (或C: 中的任何其他命令),該命令不會返回錯誤。
如何讓 Process.Start 在 System32 中運行這些命令
system32 在較新的系統(尤其是 64 位 Windows 7 或 2008)上不是“真實的”......它是從一些內部目錄合成的,當它被訪問時,它會顯示不同的應用程序(32 對 64)不同的內容......
我測試運行了代碼,將可執行文件更改為我位於 C:\\Windows\\System32 目錄中的可執行文件。 它運行正常。 (我正在運行 Win 7 64 位)
建議:確保該 exe 存在於 C:\\Windows\\System32 中,或者您試圖從中運行它的任何位置。 另外,如果您是從 Internet 下載的,請確保它已解鎖(右鍵單擊 exe > 屬性 > 解鎖)。
string command = System.IO.Path.Combine(Environment.SystemDirectory, "wscript.exe");
string args1 = ""; //Appropriate arguments
ProcessStartInfo psInfo = new ProcessStartInfo(command);
psInfo.Arguments = args1;
psInfo.Verb = "runas";
try
{
Process p = Process.Start(psInfo);
p.WaitForExit();
//return "Try Done";
}
catch (Exception e)
{
//return e.Message;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.