title: run a cmd command as administrator via context menu on windows 10
body: <p>I need some help: I want to create an explorer context menu option(while right clicking on a folder) for my program to run it as administrator from the context menu by using this .bat file:</p>
  
  <pre><code>@ECHO OFF
  :: Choose the correct command processor for the current operating system
  SET _cmd=
  :: Variable to add shortcut to menu entry (NT only,
  :: since COMMAND.COM cannot echo an ampersand)
  SET _=
  ECHO.%COMSPEC% | FIND /I "command.com" &gt;NUL
  IF NOT ERRORLEVEL 1 SET _cmd=command.com /e:4096
  ECHO.%COMSPEC% | FIND /I "cmd.exe" &gt;NUL
  IF NOT ERRORLEVEL 1 SET _cmd=cmd.exe
  IF [%_cmd%]==[cmd.exe] SET _=^&amp;
  :: Create a temporary .REG file
  &gt; %TEMP%.\DEFOPEN.REG ECHO REGEDIT4
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO.
  :Print
  ECHO Adding "Explorer context menu option" entry
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO [HKEY_CLASSES_ROOT\Directory\shell\ourprog]
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO @="%_%Add to Hot Backup (A.A.T Anti-Ransomware)"
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO.
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO [HKEY_CLASSES_ROOT\Directory\shell\ourprog\command]
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO @="java -jar C:\users\Tamir Naaman\Desktop\A.A.T-Anti-Ransomware.jar -backup \"%%L\"
  &gt;&gt;%TEMP%.\DEFOPEN.REG ECHO.
  :: If neither COMMAND.COM nor CMD.EXE then skip this step
  IF [%_cmd%]==[] GOTO Merge
  :: Merge the temporary .REG file
  :Merge
  START /WAIT REGEDIT /S %TEMP%.\DEFOPEN.REG
  :: Delete the temporary .REG file
  DEL %TEMP%.\DEFOPEN.REG
  :: Ready
  GOTO End
  :: Clean up variables and quit
  :End
  SET _cmd=
  SET _=
  </code></pre>
  
  <p>and I got this error message after I tried to click the option in the context menu:<br>
  <a href="https://i.stack.imgur.com/Idga6.png" rel="nofollow noreferrer">error message</a></p>
  
  <p>The registry picture:</p>
  
  <p><a href="https://i.stack.imgur.com/6aZGg.png" rel="nofollow noreferrer">Registry picture</a></p>
  
  <p>The registry picture:</p>
  
  <p><a href="https://i.stack.imgur.com/CaAey.png" rel="nofollow noreferrer">Registry picture</a></p>
  
  <p>I just noticed  that the default value is not set, how can i fix my code?</p>
  
  <p>Can you help me find the problem in my batch file?</p>
  
  <p>Thank you for your help!</p>