CreateProcessWithLogonW

Discussion in 'ASP .Net Security' started by Todd B, Jul 26, 2005.

  1. Todd B

    Todd B Guest

    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.
     
    Todd B, Jul 26, 2005
    #1
    1. Advertising

  2. Todd B

    Todd B Guest

    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.

    "Todd B" wrote:

    > 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.
    >
     
    Todd B, Aug 1, 2005
    #2
    1. Advertising

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
    Replies:
    5
    Views:
    2,464
    Matthew Wieder
    Aug 20, 2003
  2. Benjamin Bittner

    Calling CreateProcessWithLogonW

    Benjamin Bittner, Jul 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    3,278
    =?Utf-8?B?QWxzdGVyc2pv?=
    Jul 5, 2004
  3. =?Utf-8?B?VG9kZCBC?=

    CreateProcessWithLogonW

    =?Utf-8?B?VG9kZCBC?=, Aug 1, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    665
    =?Utf-8?B?VG9kZCBC?=
    Aug 1, 2005
  4. Benjamin Bittner

    Calling CreateProcessWithLogonW

    Benjamin Bittner, Jul 2, 2004, in forum: ASP .Net Security
    Replies:
    18
    Views:
    756
    Alstersjo
    Jul 16, 2004
Loading...

Share This Page