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 CreateProcessWi thLogonW(). 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...a lmost.
When the process created with CreateProcessWi thLogonW ends, we need to get
the exit code of the program. Using the System.Diagnost ics.Process class, I
was previously able to do so as such:
myProcess.Start ();
myProcess.WaitF orExit();
return myProcess.ExitC ode;
Unfortunately, starting the process using CreateProcessWi thLogonW 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 CreateProcessWi thLogonW() in an ASP.NET application?
A sample code listing follows:
dim proc as System.Diagnost ics.Process
proc = VastAbyss.RunAs .StartProcess
( "username", "domain", "password", "c:\test\myprog ram.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.WaitForExi t()
return proc.ExitCode
I've also tried using the API call GetExitCodeProc ess(); 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.