title: How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
body: <p>I want my batch file to only run elevated. If not elevated, provide an option for the user to relaunch batch as elevated.</p>
  
  <p>I'm writing a batch file to set a system variable, copy two files to a <em>Program Files</em> location, and start a driver installer. If a Windows&nbsp;7/Windows&nbsp;Vista user (<a href="http://en.wikipedia.org/wiki/User_Account_Control" rel="noreferrer">UAC</a> enabled and even if they are a local admin) runs it without right-clicking and selecting "Run as Administrator", they will get 'Access Denied' copying the two files and writing the system variable.</p>
  
  <p>I would like to use a command to automatically restart the batch as elevated if the user is in fact an administrator. Otherwise, if they are not an administrator, I want to tell them that they need administrator privileges to run the batch file. I'm using <strong>xcopy</strong> to copy the files and <strong>REG ADD</strong> to write the system variable. I'm using those commands to deal with possible Windows&nbsp;XP machines. I've found similar questions on this topic, but nothing that deals with relaunching a batch file as elevated.</p>