我正在更新已存在的旧进程,其工作方式如下:
用户提交一个运行以下asp的表单(简化,名称已更改):
<%
set rb = Server.CreateObject("RecordBuilder.SomeObject")
rb.Calculate()
rb.StartProcess()
%>
RecordBuilder.SomeObject
是一个旧的VB6 DLL,我没有VB6,所以我把它转换为VB.NeT 4.0
对Calculate()
的调用按预期工作,对StartProcess()
的调用失败。
StartProcess()
如下:
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
调用proc.Start()
时失败,但是如果我将测试ASP复制到.vbs
文件,它将按预期工作。
我更改了d:\App\RecordProcessor.exe
的权限,以授予对群组Everyone
的执行权限。
答案 0 :(得分:0)
检查网站的匿名用户帐户是否具有d:\app
文件夹及其可能涉及的任何其他文件夹的必要权限。
我发现缺少的一件事是proc.WaitForExit()
后的proc.Start()
。
您可能想要这样,这样您也可以从过程本身捕获错误:
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