Tech Off Thread

9 posts

Exception using CreateProcessWithLogonW from ASP.NET

Back to Forum: Tech Off
  • CareBear

    I've just recently posted the same question on the ASP.NET forums, been read by many people but no answers so I thought I'd give Channel9 a go:

    Hope any of this is understandable!

    I have a .exe I need to execute from a web project. The application needs license registration which is somehow related to the users profile. I'm not sure if the license details is stored in Windows registry or not, but it is at least related to the profile somehow.

    I have wrapped the win32 function CreateProcessWithLogonW in C# and I've tried to call it using LOGON_WITH_PROFILE. Running this function from a Windows Forms application works fine, but running from ASP.NET displays a dialog:

    test.exe - Application Error
    The application failed to initialize properly (0xc0000142). Click on OK to terminate the application.

    I have recently moved this solution from an Windows 2000 Server to a Windows 2003 Server, and I was previously using System.Diagnostics.Process.Start() which ran the .exe using ASPNET account. What I did on this configuration, was to manually set password for ASPNET account, change the Local Machine Policy to allow ASPNET to logon, then filled out the license details for the application. This worked fine, but on IIS6.0 the web application runs using NETWORK SERVICE by default.

    To get around this, I tried to change the application pool to run as the dedicated user I created. This seemed to work, but it turns out the application runs in "DEMO" mode, aka. it doesn't load the PROFILE of the user when the web application runs in a pool with a specific user.

    So what I need, is to run an .exe using a certain Windows profile from a web application.

    I'm open for suggestions and appriciate any help,

  • Homer

    I have had problems with ASP.Net security on several applications recently.  The solution for me was simple.  In IIS, I needed to choose properties, Directory Security and edit anonymous access and authentication control.  I unchecked allow anonymous access.  This solved my problem.  It casued the application to authenticate using the AD user account for the connecting user.  I'm not sure if this adresses your issue, but I hope it helps.

  • CareBear

    Thanks for the response, but I doubt it helps me. I'm running this code from within a Web Service which is being called by another website elsewhere, so there is no authentication on IIS level.


  • clint_hill

    You may want to look into PrincipalPermission and Principal under the System.Security namespace. Look into Impersonate() method. There is a good example of this in MSDN library.

  • CareBear

    I should have mentioned that in the same project I'm also using Word interop where I'm using the Impersonate() method. This works fine cause I'm creating instances of WordApplication and just doing operations directly on the object. This makes it run as the impersonated user.

    This does however, not apply when you execute an external process using Process.Start().

    I use the win32 api function LogonUser() in advapi32.dll to get the user Token, which I then use in the Impersonate(hToken) method.

    So .. still not working Expressionless

    Thanks anyway,

  • alstersjo

    I am struggling with the same problem. Did you solve it?

  • billh

    You may also want to look into the CreateProcessWithLogonClassExceptionIncludeUserStaticVerify method.

  • alstersjo

    Hi, thanks for your answer, but frankly I didn't find out how to do this. Can you plese point me in the correct direction?
    //Regards Henrik

  • avheerwaarde

    Got the same problem. The started process tries to inherit the desktop, but none is there.

    It Was solved by adding the next line:

    si.desktop = @"winsta0\default";

    where si is the startupinfo structure.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.