title: Batch: run as administrator from mapped network drive
body: <p>So, I have that common problem that everyone seems to have of trying to run a batch file stored on a network drive as an administrator.  I have scoured the internet and there are some 'workarounds' but I am not sure how to apply them if I can at all.</p>
  
  <p><strong>Actual task:</strong> batch file (lets call this batch #1) to copy a file "mms.cfg" from a network drive (same dir as batch) to system32 and syswow64.  Of course, these folders are protected thus the need to run as admin.  But when you run as admin, the mapped network drive doesn't exist for the "admin" account and the batch craters.  </p>
  
  <p>In this particular instance batch #1 runs a silent install of flash. After that it needs to copy a config file to the aforementioned protected folders to disable its auto-update feature since our standard users can't run the updates which flash would otherwise nag them about (why can't adobe just add a switch to their installer to turn off this feature?).  </p>
  
  <p><strong>What I've tried:</strong> I have seen the work around to set <code>EnableLinkedConnections=1</code> in the registry, but I need to deploy this batch file to numerous PCs on a network and cannot change that registry key on each one.  </p>
  
  <p>I've also tried to re-map the directory after I run as admin.  Again, the batch craters since it is being ran from a mapped network drive and "administrator" doesn't know this drive exists, thus the crash before I get the chance to map the drive (via <code>pushd</code> or whatever).</p>
  
  <p>I cannot simply copy the batch to the local PC to run it each time as: <strong>1)</strong> it does other tasks (starts two installers), <strong>2)</strong> the batch file itself is being ran from another batch (denote as batch #2) that is going down a list of software updates and applying them silently,  <strong>3)</strong> this is to apply a series of updates where I (domain admin) would log into each PC and run batch #2 to update a series of programs (domain auto-maps directory to updates, thus I navigate to I:\updates and run it). </p>
  
  <p><strong>End result I'm hoping for:</strong> Essentially this boils down to how do I run a batch stored on a mapped network drive with administrative rights?  Is there any way to do this on any given networked machine or am I reduced to copying the config file manually to system32 and syswow64 for each PC that I want to update?</p>
  
  <p><strong>TLDR:</strong> Run batch stored on a mapped network drive as admin without it cratering.</p>
  
  <p>If I was unclear or need to provide more information I will do my best to check back.  Thank you in advance for any help!</p>
  
  <hr>
  
  <p><em><strong>UPDATE</strong></em> - So, I was able to get <code>EnableLinkedConnections=1</code> set across our computers in the domain via GPO.  However, I have noticed another interesting issue:  when you right-click &amp; run as admin, it runs fine.  However, including the below code to auto-request admin rights now fails when you just run the script.  Maybe I'm just missing something simple? </p>
  
  <p>Again, thanks in advance for any help!</p>
  
  <pre><code>:: BatchGotAdmin
  :-------------------------------------
  REM  --&gt; Check for permissions
  &gt;nul 2&gt;&amp;1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  
  REM --&gt; If error flag set, we do not have admin.
  if '%errorlevel%' NEQ '0' (
      echo Requesting administrative privileges...
      goto UACPrompt
  ) else ( goto gotAdmin )
  
  :UACPrompt
      echo Set UAC = CreateObject^("Shell.Application"^) &gt; "%temp%\getadmin.vbs"
      set params = %*:"=""
      echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 &gt;&gt; "%temp%\getadmin.vbs"
  
      "%temp%\getadmin.vbs"
      del "%temp%\getadmin.vbs"
      exit /B
  
  :gotAdmin
      pushd "%CD%"
      CD /D "%~dp0"
  :--------------------------------------
  </code></pre>