我有一个使用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