Discussion in 'ASP .Net' started by =?Utf-8?B?VG9kZCBC?=, Aug 1, 2005.

  1. Hello,

    I posted this in the 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 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:

    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.
    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.
    =?Utf-8?B?VG9kZCBC?=, Aug 1, 2005
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew Wieder

    ASPNET and CreateProcessWithLogonW

    Matthew Wieder, Aug 18, 2003, in forum: ASP .Net
    Matthew Wieder
    Aug 20, 2003
  2. Benjamin Bittner

    Calling CreateProcessWithLogonW

    Benjamin Bittner, Jul 1, 2004, in forum: ASP .Net
    Jul 5, 2004
  3. Benjamin Bittner

    Calling CreateProcessWithLogonW

    Benjamin Bittner, Jul 2, 2004, in forum: ASP .Net Security
    Jul 16, 2004
  4. Todd B


    Todd B, Jul 26, 2005, in forum: ASP .Net Security
    Todd B
    Aug 1, 2005

Share This Page