« Previous Next »

Thread: How to run msdeploy with elevated privileges (as administrator)

Last post 12-03-2008 4:42 PM by anjee. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 12-02-2008, 2:36 PM

    How to run msdeploy with elevated privileges (as administrator)

    Hello,

    I am currently working on a deployment web app, which wraps msdeploy. I have run successfully from my local machine. However, when deployed to our dev server, the deployment app doesn't work. Files are not copied and I get the following event log entry:

    Event Type: Error
    Event Source: Application Error
    Event Category: (100)
    Event ID: 1000
    Date:  12/1/2008
    Time:  4:48:23 PM
    User:  N/A
    Computer: DWEBAPP01.xxxx.Com
    Description:
    Faulting application msdeploy.exe, version 7.1.300.0, faulting module 490650db, version KERNEL32.dll, fault address 0x6.0.6001.18000.

    I'm using IIS7 on our dev server (running Windows Server 2008), and my web development is using VS2008. In my deployment web app, I create a process and start it, using the following code:

    mDeployProcess = new Process
    {
        StartInfo = new ProcessStartInfo
        {
            FileName = cDeployCommandPath,
            Arguments = DeployParameters(),
            UseShellExecute = false,
            CreateNoWindow = true,
            UserName = cBuilder,     
            Password = GetSecurePassword(cBuilderPassword)
        }

    };
    mDeployProcess.Start();

    The FileName parameter points to msdeploy.exe, and the Arguments parameter ends up as follows:

    -verb:sync -source:contentPath=\\builderpc\TeamCityBuildArtifacts\xxx.EnterpriseServices\xxx.EnterpriseServices_Release\405\ -dest:contentPath=\\dwebapp01\c$\inetpub\wwwroot\xxx.EnterpriseServices,computerName=DWEBAPP01,username=builder,password=builder

    I can run msdeploy from a command prompt on the dev server using these parameters successfully, if I select "Run as administrator" when opening the command prompt. How do I make my web app run msdeploy as an administrator? I've read some posts about the need to use elevated privileges, but I don't know how to do this, or even if that is the correct solution. Any help much appreciated.

    Thanks,
    Dean

  • 12-02-2008, 11:43 PM In reply to

    • yaminij
    • Top 50 Contributor
    • Joined on 09-25-2007, 12:41 AM
    • Posts 185

    Re: How to run msdeploy with elevated privileges (as administrator)

    Thanks
    Yamini Jagadeesan, SDET, Microsoft IIS Team
  • 12-03-2008, 1:48 PM In reply to

    Re: How to run msdeploy with elevated privileges (as administrator)

    Thanks, I did look that over. There's a lot there. I guess I'm not even sure now if this is possible, so I'll pose the question:

    Is it possible to programmatically run a process that requires "run as admin", and suppress the elevation prompt?

    My process does have the proper authorization, I just don't know how to tell Windows that it does, so that the process can run successfully in the background without any user interaction.

    Thanks,
    Dean

  • 12-03-2008, 4:42 PM In reply to

    • anjee
    • Top 500 Contributor
    • Joined on 11-28-2008, 4:44 PM
    • Posts 17

    Re: How to run msdeploy with elevated privileges (as administrator)

    This is may be helpful to you I found in other forum.....

    for more help use the following link: http://www.pinvoke.net/default.aspx/advapi32/CreateProcessWithLogonW.html

     

     

    If you want to start a process with another account, you could use the Windows API CreatePorcessWithLoginW, like the codes in C#:Code Snippet

     [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

     public struct StartupInfo

     {

     public int cb;

     public String reserved;

     public String desktop;

     public String title;

     public int x;

     public int y;

     public int xSize;

     public int ySize;

     public int xCountChars;

     public int yCountChars;

     public int fillAttribute;

     public int flags;

     public UInt16 showWindow;

     public UInt16 reserved2;

     public Byte reserved3;

     public IntPtr stdInput;

     public IntPtr stdOutput;

     public IntPtr stdError;

     }

     

            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

            public struct ProcessInformation

            {

                public IntPtr process;

                public IntPtr thread;

                public int processId;

                public int threadId;

            }

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

            public static extern bool CreateProcessWithLogonW(

               String userName,

               String domain,

               String password,

               UInt32 logonFlags,

               String applicationName,

               String commandLine,

               UInt32 creationFlags,

               UInt32 environment,

               String currentDirectory,

               ref  StartupInfo startupInfo,

               out ProcessInformation processInformation);

     

    Thanks,
    Anjee.

Page 1 of 1 (4 items)
Microsoft Communities