我有一個使用process.start調用可執行文件(Graphviz)的asp.net應用程序。所有在我的開發環境中運行良好,但是當我轉向生產時,我無法讓程序運行。這是細節。需要哪些權限才能通過asp.net應用程序啓用process.start?
我創建了這個簡單的子來顯示問題。
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim ProcessInfo As ProcessStartInfo
ProcessInfo = New ProcessStartInfo
'ProcessInfo.Domain = "xxxxxxx"
ProcessInfo.UserName = "xxxxxx"
Dim PwdString As String = "xxxxxxx"
Dim newPass As System.Security.SecureString
newPass = New System.Security.SecureString
For Each c As Char In PwdString
newPass.AppendChar(c)
Next c
ProcessInfo.Password = newPass
'ProcessInfo.FileName = """C:\Windows\System32\Notepad.exe"""
'ProcessInfo.FileName = """C:\Test.bat"""
ProcessInfo.FileName = """C:\Program Files (x86)\Graphviz2.30\bin\dot.exe"""
ProcessInfo.Arguments = " -Kdot -Tsvg C:\Test.dot -pC:\Test.svg"
ProcessInfo.RedirectStandardOutput = True
ProcessInfo.UseShellExecute = False
ProcessInfo.CreateNoWindow = True
Dim Process As Process
Process = New Process
Process.StartInfo = ProcessInfo
Process.Start()
'Wait until the process passes back an exit code
Process.WaitForExit()
Try
Dim ProcessResults As String = Process.StandardOutput.ReadToEnd
Output.Text = ProcessResults
Catch ex As Exception
Output.Text = ex.ToString
End Try
End Sub
這裏有三種情況。首先,我正在測試簡單地開始記事本。 - 開發工作 - 生產工程(這是我能得到生產工作的唯一情況)
其次,我創建了一個打開一個記事本文檔簡單的批處理文件。 (記事本C:\ test.dot)
- 發展工作
- 生產不起作用
第三,我已經打電話的Graphviz的dot.exe。這是我想要在另一個頁面上工作的。
- 發展工作
- 生產不起作用
在所有的情況下,生產不能正常工作,我可以重現此問題 - 如果我添加一個冒充=真到我的web.config ,那麼我不會收到任何錯誤。該頁面運行,如果它是成功的。
如果我不添加冒充配置,但不要添加憑據到ProcessInfo對象,那麼頁面將再次運行沒有錯誤。雖然這個過程並不是從生產開始的。
如果我不添加impersonate或ProcessInfo憑據,那麼我會收到錯誤消息。這是錯誤輸出。
訪問被拒絕
說明:在當前Web請求的執行過程中發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
Exception Details: System.ComponentModel.Win32Exception: Access is
denied
Source Error:
Line 36: Process = New Process
Line 37: Process.StartInfo = ProcessInfo
Line 38: Process.Start()
Line 39:
Line 40: 'Wait until the process passes back an exit code
Source File: C:\Inetpub\vhosts\leapfrogbi.com\httpdocs\test\ProcessStart.aspx.vb Line: 38
Stack Trace:
[Win32Exception (0x80004005): Access is denied]
System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) +2161
System.Diagnostics.Process.Start() +150
Test_ProcessStart.Page_Load(Object sender, EventArgs e) in C:\Inetpub\vhosts\leapfrogbi.com\httpdocs\test\ProcessStart.aspx.vb:38
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
我已經嘗試了多種安全相關的設置。目前我的應用程序池正在以本地管理員身份運行。我也嘗試將所有人添加到管理員組中,試圖查看安全是否是根本問題。
另外,我正在使用Plesk管理我的域。我已經廣泛搜尋可能影響這種情況的任何選項,並且尚未發現。同樣,當進行簡單的調用以啓動記事本時,過程開始在生產中起作用。在沒有更詳細的日誌的情況下很難縮小這個範圍。
非常感謝您提供的任何幫助。這讓我瘋狂。
謝謝Aristos。我按照您的建議進行了操作,但應用程序池標識目前是本地管理員組的一部分。 – DataMe 2013-02-21 17:16:06
我驗證了這是Security.Windowsidentity.GetCurrent.User返回的相同用戶。我也繼續前進,並明確給予與請求相關的文件相同的用戶權限,但結果相同。請記住,我可以使用管理員帳戶運行該應用程序,但該過程確實運行,但記事本啓動的第一個示例除外。 – DataMe 2013-02-21 17:42:29
取消我的最後一個。我發現了一個用戶沒有權限的文件。批處理文件運行。我將進一步測試目標exe和報告。 – DataMe 2013-02-21 17:51:16