Starting a Process with specified username

Last post 12-20-2006 1:20 AM by GeorgeZ. 3 replies.

Sort Posts:

  • Starting a Process with specified username

    12-17-2006, 11:32 PM
    • Loading...
    • pauldb
    • Joined on 12-18-2006, 4:04 AM
    • Posts 2

    I'm trying to start a process with a specified username and the following snippet

    a) works fine from a Console app.
    b) works fine from a file-based ASP app but
    c) gives 0000146 (failed to initialize) from an Http ASP2 app

    System.Security.SecureString ss = new System.Security.SecureString();
    ss.AppendChar('a');
    System.Diagnostics.Process.Start("Notepad.exe", "a", ss, "XP1");

    I've tried all the IIS settings (its IIS5) to accommodate it (Integerated Windows, no anonymous, even impersonation) but still have no luck.

    Any help appreciated.

     

    Filed under: , ,
  • Re: Starting a Process with specified username

    12-18-2006, 11:57 PM
    Answer
    • Loading...
    • GeorgeZ
    • Joined on 11-16-2006, 1:09 AM
    • UpC
    • Posts 552

    Hi, 

    Win32 API CreateProcessWithLogonW support Starting a Process with specified username.

    You can DllImport it in .net code.

    [DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]

    private static extern bool CreateProcessWithLogonW(String lpszUsername,

    String lpszDomain, String lpszPassword, int dwLogonFlags, string

    applicationName, StringBuilder commandLine, uint creationFlags,

    IntPtr environment, string currentDirectory, ref StartUpInfo sui,

    out ProcessInformation processInfo);

    And there is existing class doing so:

    http://www.codeproject.com/csharp/RunAs.asp

    I think this worth a try if your code still fails.


  • Re: Starting a Process with specified username

    12-19-2006, 2:38 PM
    • Loading...
    • pauldb
    • Joined on 12-18-2006, 4:04 AM
    • Posts 2

    Hi George

    Thanks for the shot, I tried it in simplified form pasting in what I needed from the CodeProject demo into an IIS-based ASP2 web app.

                System.Diagnostics.Process proc = RunAs.StartProcess("a","XP1","a","notepad.exe");
    Unfortunately it gives the same error - the dreaded "application failed to initialize".
    Again, it works fine in a file-based web site.
    I suspect that the .NET2 ProcessStartInfo/Process combination wraps up CreateProcessWithLogonW.

    I can't help thinking its something in ASP.NET (1.1 & 2) that prevents one from kicking off a process from a web page - because of the security implications maybe?

    Paul

     

  • Re: Starting a Process with specified username

    12-20-2006, 1:20 AM
    • Loading...
    • GeorgeZ
    • Joined on 11-16-2006, 1:09 AM
    • UpC
    • Posts 552

    I'm not very certain where is the problem.

    However I think ASP.NET Impersonation is another way that worth a trial.

    You can impersonate your application then start your program.

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter