CreateProcessWithLogonW

G

Guest

Hello,

I posted this in the aspnet.security group a few days ago but haven't
received any feedback, so I thought I would try this group. Apologies if
this is the wrong place.


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

I've also tried using the API call GetExitCodeProcess(); it will return the
STILL_ACTIVE constant until the process terminates, but then appears to throw
an exception instead of getting the exit code. Strangely, even though I have
the call inside a try-catch block, it is not being caught there.

Any insights would be greatly appreciated.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top