title: How to run a CruiseControl task as an administrator in Windows Server 2008
body: <p>I'm currently using <a href="http://en.wikipedia.org/wiki/CruiseControl" rel="nofollow noreferrer">CruiseControl.NET</a> to automate my build. We have two different ways to build a solution in my build environment - one is through the <a href="http://en.wikipedia.org/wiki/Keil_%28company%29" rel="nofollow noreferrer">Keil</a> uVision4 IDE, the other is through Visual Studio 2008.</p>
  
  <p>I've successfully gotten the Visual Studio solution to build properly using CruiseControl.NET and have created a batch file which properly uses Keil's uVision command line interface to compile my uvproj Project (<a href="http://www.keil.com/support/man/docs/uv4/uv4_commandline.htm" rel="nofollow noreferrer">compilation details here</a>).</p>
  
  <h2>Problem Description</h2>
  
  <p>1)  I can successfully execute the build script on my Windows 2008 server and build the project if I create a command prompt with administrator privileges (I'm doing this manually - start -> run -> cmd with ctrl-shift-enter to run as admin).</p>
  
  <p>2) However, if I create a command prompt <em>without</em> administrator privileges, and attempt to execute the batch file, the batch file won't work unless I accept the prompt asking me to confirm admin rights are required to run the batch script.</p>
  
  <p>How do I automatically execute a batch file as an administrator through CruiseControl?</p>
  
  <p>Is this something that could be automated using the <a href="http://technet.microsoft.com/en-us/library/cc771525%28v=ws.10%29.aspx" rel="nofollow noreferrer">RunAs</a> command?</p>
  
  <hr>
  
  <h2>Technical details</h2>
  
  <p>1) The batch file being executed is pretty simple - it deletes the old output and re-makes the output, creating a build log file in the location below.</p>
  
  <pre><code>set BuildLogLocation=BuildLog\BuildLog.txt
  
  echo on
  cd ../..
  cd PTM
  rmdir /s /q output
  mkdir output
  mkdir BuildLog
  C:\Keil\UV4\UV4.exe -r myProj.uvproj -o %BuildLogLocation%
  
  echo ErrorLevel of build is %ERRORLEVEL%
  echo build complete, see %BuildLogLocation%
  </code></pre>
  
  <p>2) Currently I'm looking to use the Exec functionality to run the Keil build script above:</p>
  
  <pre><code>&lt;Exec&gt;
      &lt;Command&gt;C:\myProject\Build\KeilBuild\BuildScript.bat&lt;Command/&gt;
      &lt;buildTimeoutSeconds&gt;600&lt;buildTimeoutSeconds/&gt;
      &lt;!-- Details about error codes can be found here:
      http://www.keil.com/support/man/docs/uv4/uv4_commandline.htm --&gt;
      &lt;successExitCodes&gt;0,1&lt;/successExitCodes&gt;
  &lt;Exec/&gt;
  </code></pre>
  
  <p>Related questions:</p>
  
  <ul>
  <li><em><a href="https://electronics.stackexchange.com/questions/12404">How can I use a build server with Keil uVision4 (MDK-ARM), script a build, use a makefile?</a></em> (<a href="https://electronics.stackexchange.com/about">Electrical Engineering</a>)</li>
  <li><em><a href="https://stackoverflow.com/questions/5233389">Execute a command-line command from CruiseControl.NET</a></em> (<a href="https://stackoverflow.com/about">Stack&nbsp;Overflow</a>)</li>
  </ul>