3

我有一个 asp.net 应用程序,它使用 process.start 来调用可执行文件(Graphviz)。在我的开发环境中一切正常,但是当我进入生产环境时,我无法让该过程运行。这是详细信息。

我创建了这个简单的子来显示问题。

    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。这就是我试图在另一个页面上工作的内容。

  • 开发工作
  • 生产不工作

在生产不起作用的所有情况下,我都可以重现此行为 - 如果我将 impersonate = true 添加到我的 web.config,那么我不会收到任何错误。页面就像成功一样运行。

  • 如果我不添加模拟配置,而是将凭据添加到 ProcessInfo 对象,那么页面将再次运行而不会出现错误。但是,该过程并未在生产中开始。

  • 如果我不添加模拟或 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 来管理我的域。我已经广泛搜索了可能会影响这种情况的任何选项,但尚未找到。同样,当简单地调用启动记事本时,进程启动确实在生产中起作用。如果没有更详细的日志,很难缩小范围。

提前感谢您提供的任何帮助。这让我发疯了。

4

2 回答 2

3

找到运行站点的池,并查看正在运行的用户。

如果您不能这样做,您可以运行此代码来查看您的池正在运行的用户:

var user = System.Security.Principal.WindowsIdentity.GetCurrent().User;
var userName = user.Translate(typeof(System.Security.Principal.NTAccount));

然后授予该用户运行这些文件的权限

参考:如何找出我的 ASP.NET 代码在哪个帐户下运行?

于 2013-02-21T10:54:12.730 回答
0

我不使用进程,使用 shell 并且它运行成功。

  1. 创建一个包含您的命令的批处理文件。不要将批处理保存在系统文件夹中。

  2. 在 IIS 中,打开运行网站的应用程序池的设置对话框。将进程池的 ID 设置为“localsystem”。

  3. 使用 shell("path\batchfile") 执行批处理文件。

于 2017-01-20T03:04:04.773 回答