开发者

Cannot create a process in a COM object from an asp site

I'm updating an old process that already exists, which works as follows:

The user submits a form which runs the following asp (simplified, names changed):

    <%  
    set rb = Server.CreateObject("RecordBuilder.SomeObject")  
    rb.Calculate()  
    rb.StartProcess()  
    %>

The RecordBuilder.SomeObject was an old VB6 DLL, I don't have VB6, so I converted it to VB.NeT 4.0

The call to Calculate() works as expected, the call to StartProcess() fails.

StartProcess() is the following:

Public Function 开发者_高级运维StartProcess()
    Try
        strProcess = "Starting process"
        Dim proc = New Process()
        proc.StartInfo.RedirectStandardOutput = True
        proc.StartInfo.UseShellExecute = False
        proc.StartInfo.CreateNoWindow = True
        proc.StartInfo.FileName = "d:\App\RecordProcessor.exe"

        Dim procHandle = proc.Start()
        strProcess = "Started process"
    Catch ex As Exception
        Err.Raise(vbObjectError + 9999, "RecordBuilder.SomeObject", strProcess & " failed: " & ex.Message & "<hr />Stack Trace:<br />" & ex.StackTrace)
    End Try
End Function

This fails with the call to proc.Start(), however if I copy the test ASP to a .vbs file it will work as expected.

I have changed the permissions on d:\App\RecordProcessor.exe to grant execute permission to the group Everyone.


Check that the website's anonymous user account has the requisite permissions on the d:\app folder and any other folders that it may be touching.

One thing I notice that's missing is proc.WaitForExit() after your proc.Start().

You probably want that so you can capture errors from the process itself as well:

Dim stdError As New String
Try
    strProcess = "Starting process"
    Dim proc = New Process()
    proc.StartInfo.RedirectStandardOutput = True
    proc.StartInfo.RedirectStandardError = True
    proc.StartInfo.UseShellExecute = False
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.FileName = "d:\App\RecordProcessor.exe"

    Dim procHandle = proc.Start()
    strProcess = "Started process"

    proc.WaitForExit()

    stdError = proc.StandardError.ReadToEnd()
    If stdError.Length > 0 Then
       '' So long since I did VB so next line might need tweaked
       Err.Raise(vbObjectError, "Caught StdError", stdError)
    End If
Catch ex As Exception
    Err.Raise(vbObjectError + 9999, "RecordBuilder.SomeObject", strProcess & _
         " failed: "  & ex.Message & "<hr />Stack Trace:<br />" & ex.StackTrace)
End Try
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜