从 ASP.NET Webform 启动后控制台应用程序崩溃
我需要从 asp.net webforms 页面触发控制台应用程序 (exe) 文件。显然,主要问题是权限,现在我只是尝试通过让 asp.net 服务模拟主管理员帐户来实现此目的。一旦我能让它以稳定的方式工作,我将设置它自己的用户和权限。现在,我非常感谢您帮助我完成这项工作。
这就是我所拥有的。
网络表单代码。
Dim p As New Process()
p.StartInfo.UseShellExecute = False
p.StartInfo.FileName = locn & exeName
p.StartInfo.CreateNoWindow = True
p.StartInfo.Arguments = GetTaskID
p.StartInfo.UserName = "adminuserid"
p.StartInfo.Domain = "domain"
Dim pw As New System.Security.SecureString
For Each ch As Char In "adminuserpassword"
pw.AppendChar(ch)
Next
p.StartInfo.Password = pw
p.StartInfo.WorkingDirectory = "directory"
p.StartInfo.RedirectStandardError = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Normal
p.StartInfo.LoadUserProfile = True
p.Start()
p.WaitForExit()
从按钮单击事件运行此代码成功启动了 EXE,我可以在服务器上的进程管理器中看到它。然而,该进程仅运行约 3 秒,然后关闭。
事件日志在 EXE 崩溃/终止后显示此信息:
应用程序错误: 错误应用程序 BlueLimeConsoleApp.exe,版本 1.0.0.0,时间戳 0x4d0ba5e2,错误模块 KERNEL32.dll,版本 6.0.6001.18000,时间戳 0x4791a7a6,异常代码 0xc0000142,错误偏移量 0x00009cac,进程 ID 0x10e8,应用程序启动时间 0x 01cb9e14d0c53e0c。
系统事件: 应用程序弹出窗口:BlueLimeConsoleApp.exe - 应用程序错误:应用程序无法正确初始化 (0xc0000142)。单击“确定”终止应用程序。
因此,似乎我能够启动 EXE,但它无缘无故地崩溃了。
EXE 中的代码是:
Module Module1
Sub Main(ByVal args As String())
For i As Integer = 0 To 10000
Console.WriteLine("hello world")
System.Threading.Thread.Sleep(1000)
Next
End Sub
End Module
此外,我试图捕获 StandardError 和 StandardOutput 消息用于测试目的,并且两者都返回空值。
此外,EXE 可以通过 RDC 直接在服务器上启动,并且运行得很好。
我已经浪费了近 2 天的时间试图让它发挥作用,此时我非常需要一些对这项工作有经验的意见。我什至愿意向找到解决方案的人赠送 50 美元作为答谢礼物!
谢谢, 托德
I need to trigger a Console App (exe) file from a asp.net webforms page. Obviously the main issue is permissions, and for now I'm just trying to get this working by letting the asp.net service impersonate the main Administrator account. Once I can get it working in a stable fashion, I'll set up it's own user and permissions. For now I would really appreciate assistance in getting this working.
Here's what I have.
Web Form Code.
Dim p As New Process()
p.StartInfo.UseShellExecute = False
p.StartInfo.FileName = locn & exeName
p.StartInfo.CreateNoWindow = True
p.StartInfo.Arguments = GetTaskID
p.StartInfo.UserName = "adminuserid"
p.StartInfo.Domain = "domain"
Dim pw As New System.Security.SecureString
For Each ch As Char In "adminuserpassword"
pw.AppendChar(ch)
Next
p.StartInfo.Password = pw
p.StartInfo.WorkingDirectory = "directory"
p.StartInfo.RedirectStandardError = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.WindowStyle = Diagnostics.ProcessWindowStyle.Normal
p.StartInfo.LoadUserProfile = True
p.Start()
p.WaitForExit()
Running this code from a button click event successfully launches the EXE, which I can see in the Process Manager on the server. However the process only runs for about 3 seconds and then closes.
The event log shows this information following the EXE crash/termination:
Application Error:
Faulting application BlueLimeConsoleApp.exe, version 1.0.0.0, time stamp 0x4d0ba5e2, faulting module KERNEL32.dll, version 6.0.6001.18000, time stamp 0x4791a7a6, exception code 0xc0000142, fault offset 0x00009cac, process id 0x10e8, application start time 0x01cb9e14d0c53e0c.
System Event:
Application popup: BlueLimeConsoleApp.exe - Application Error : The application failed to initialize properly (0xc0000142). Click OK to terminate the application.
So, it seems as though I'm able to launch the EXE but it crashes for no apparent reason.
The code in the EXE is:
Module Module1
Sub Main(ByVal args As String())
For i As Integer = 0 To 10000
Console.WriteLine("hello world")
System.Threading.Thread.Sleep(1000)
Next
End Sub
End Module
In addition, I'm trying to capture the StandardError and StandardOutput messaging for testing purposes, and both return empty values.
Also, the EXE can be launched directly on the server via RDC and it runs just fine.
I've wasted almost 2 days trying to get this to work, and at this point I'm desperate for some experienced input on this job. I'd even be willing to throw in $50 as a thankyou gift to whoever has the solution!
Thanks,
Todd
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 Rob ZI 能够使其正常工作,一旦我删除了除以下内容之外的所有内容,它就可以在网络服务用户下成功运行。现在我只需要使用更安全的用户来运行它。
Thanks to Rob Z I was able to get this working, Once I removed everything except the following, it ran successfully under the Network Service user. Now I just need to run it with a more secure user.