title: Simple method to run a batch as Administrator using javascript
body: <p>I want to derive a simple reliable method to auto elevate a running batch without using extra VBS files or elevated shortcuts, proposed in other threads. Calling the UAC dialog from the batch via javascript ensures the short simple code. </p>
  
  <p>The script below auto elevates a user to Admin rights correctly, when Yes is chosen in the dialog, but the error dialog popups (outside of Cmd window) "<em>Windows cannot find 'test.bat</em>'". Can it be since the path-to-file includes spaces? How to fix the code or suppress this error popup?</p>
  
  <pre><code>@echo off
  :: test admin rights
  &gt;nul 2&gt;&amp;1 net file
  echo '%errorlevel%'
  MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute("%~nx0", '', '', 'runas', 1);close();"
  :: test admin rights
  &gt;nul 2&gt;&amp;1 net file
  echo '%errorlevel%'
  if !errorlevel! equ 0 echo Hello &gt;%temp%\tst.txt
  exit /b
  </code></pre>