通过asp.net应用程序启用process.start需要哪些权限?

时间:2013-02-21 10:46:52

标签: asp.net permissions process.start

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

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

    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中添加了impersonate = true,那么我不会再收到任何错误。页面运行就像成功一样。

  • 如果我没有添加模拟配置,但确实将凭据添加到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来管理我的域名。我已经广泛搜索了可能影响这种情况的任何选项,并且还没有找到。再次,当进行简单的调用以启动记事本时,进程启动在生产中起作用。没有更详细的日志,很难将其缩小。

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

2 个答案:

答案 0 :(得分:2)

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

如果您无法执行此操作,则可以运行此代码以查看池正在运行的用户:

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

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

参考:How to find out which account my ASP.NET code is running under?

答案 1 :(得分:0)

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

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

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

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