简体   繁体   中英

Console App crashing after being launched from ASP.NET Webform

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

Thanks to Rob ZI 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.

p.StartInfo.UseShellExecute = False
p.StartInfo.FileName = locn & exeName
p.StartInfo.Arguments = GetTaskID 
p.Start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM