title: How to silently/automatically install Desktop Experience in Azure?
body: <p>I need to install Desktop Experience in Azure Worker Role. Installing DE via the command line can be done with: </p>
  
  <pre><code>c:\servermanagercmd -install Desktop-Experience
  </code></pre>
  
  <p>And then a reboot is required. </p>
  
  <p>How can I best make this work in Azure Worker Role? </p>
  
  <hr>
  
  <p>UPDATE: </p>
  
  <p>1) Make sure to use OS Family 2 and SDK >=1.3</p>
  
  <p>2) Use elevated startup task to call included batchfile with this command: </p>
  
  <pre><code>3) servermanagercmd -install Desktop-Experience -restart -resultPath results.xml
  </code></pre>
  
  <hr>
  
  <p>I have tried </p>
  
  <p>a) to put that commandline in a batch/.cmd file and run it via an elevated startup task. Result: The worker role keeps Aborting and restarts in a neverending loop. </p>
  
  <p>b) I have tried to create a new Process() in OnStart(), under elevated runtime, something like this: </p>
  
  <p>ServiceDefinition.csdef:</p>
  
  <pre><code> Runtime executionContext="elevated"
  </code></pre>
  
  <p>WorkerRole.cs:</p>
  
  <pre><code>public override bool OnStart()
  {
     if (!System.IO.File.Exists("Startup\\InstallationFinished.txt"))
     {
  
        Process startup = new Process(); 
  
        startup.StartInfo.FileName = "Startup\\InstallDesktopExperience.cmd";
        startup.StartInfo.CreateNoWindow = true;
        startup.EnableRaisingEvents = true;
        startup.Start();
        startup.WaitForExit();
  
        System.IO.File.WriteAllText("Startup\\InstallationFinished.txt", 
              "Installation is complete.");
  
        startup.StartInfo.FileName = "Startup\\Reboot.cmd";
        startup.Start();
      }
  
      base.OnStart(); 
  }
  </code></pre>
  
  <p>InstallDesktopExperience.cmd: </p>
  
  <pre><code>servermanagercmd -install Desktop-Experience
  </code></pre>
  
  <p>Reboot.cmd:</p>
  
  <pre><code>shutdown /r
  </code></pre>
  
  <p>The result is that the Event Viewer in the Azure Worker Role shows an exception from TrustedInstaller (0xc0000005). After this error is shown in the event log, DE cannot be installed manually by opening a command line window and typing the command either. I get the error: </p>
  
  <p>Error: Installation of [Desktop Experience] failed. Attempt to install Desktop Experience failed with error code 0x80080005.  Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))</p>
  
  <p>(but it works by doing it manually in a command line window if I haven't run the code in OnStart)</p>
  
  <p>I'm lost. Thanks in advance for any and all suggestions. </p>