CreateProcessWithLogonW

T

Todd B

Hello,

I am developing an ASP.NET application that allows users to enter data using
web forms, then run an EXE when they click the appropriate button. The EXE
needs certain security rights not available to the ASPNET user.

After playing around with impersonation, I found that even using
impersonation, the child process will be run as ASPNET. So after more
digging, I found the API call CreateProcessWithLogonW(). I'm using the RunAs
class from http://www.codeproject.com/csharp/RunAs.asp and this did the trick
(after much persuasion) and everything is now working beautifully...almost.

When the process created with CreateProcessWithLogonW ends, we need to get
the exit code of the program. Using the System.Diagnostics.Process class, I
was previously able to do so as such:

myProcess.Start();
myProcess.WaitForExit();
return myProcess.ExitCode;

Unfortunately, starting the process using CreateProcessWithLogonW prevents
me from getting the exit code; I get an access denied error. Which makes
sense, since a user with stronger rights created the process, not the ASPNET
account. I've tried impersonating the same user with which I create the
process, but still get the same error.

So my question is: does anyone know of a way to get the exit code of the
process created with CreateProcessWithLogonW() in an ASP.NET application?

A sample code listing follows:

dim proc as System.Diagnostics.Process
proc = VastAbyss.RunAs.StartProcess
( "username", "domain", "password", "c:\test\myprogram.exe" )

'Here is where the trouble starts; the call to WaitForExit seems to
'succeed, but an exception is thrown on the proc.ExitCode call.
proc.WaitForExit()
return proc.ExitCode

Any insights would be greatly appreciated.
 
T

Todd B

I've looked into this a little more; I've tried substituting the API call
GetExitCodeProcess() in for the System.Diagnostics.Process.WaitForExitCall()
but that doesn't work either. I'm beginning to think there is no way to get
the exit code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top