簡體   English   中英

打開文件(C#)時拒絕Process.start()權限

[英]Process.start() permission denied when opening file (C#)

我知道有一些關於類似案例的帖子,但是我不會解釋。

我正在嘗試啟動一個從我的應用程序啟動時要求管理員特權的應用程序,該應用程序也具有管理員權限。 當我使用分配給它的按鈕啟動它時,出現類似您在下圖中看到的錯誤。

我使用的代碼是:

private void startESEA_Click(object sender, EventArgs e)
{
    // Inicio ESEA Cliente
    Process ESEA = new Process();
    ESEA.StartInfo.FileName = dESEAClient + "\\eseaclient.exe";
    ESEA.Start();
}

我在Visual Studio調試模式下遇到的錯誤 在此處輸入圖片說明

假設您沒有訪問該文件的權限,則可以強制您的應用以管理權限運行。

只需將Application Manifest FIle添加到您的項目中,然后對<requestedExecutionLevel>必要的更改。

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

或以admin身份運行特定進程:

{
   Process p = new Process();
   p.StartInfo.FileName = filepathhere;
   p.StartInfo.UseShellExecute = true;
   p.StartInfo.Verb = "runas";
   p.Start();
 }

或者你可以簡單地執行一個cmd命令:

 Process process = new System.Diagnostics.Process();
 ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
 startInfo.WindowStyle = ProcessWindowStyle.Hidden;
 startInfo.FileName = "cmd.exe";
 startInfo.Arguments = "runas /profile /user:usernamehere ""C:\programs\BBB.exe”"";
 process.StartInfo = startInfo;
 process.Start();

如果以上方法均FileAttribute ,請嘗試設置FileAttribute

 File.SetAttributes(filepath, FileAttributes.Normal);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM