I want bat file to ask if it can make changes on the computer

(I don't speak English. Hope you understand)

Hi, I have a .bat file, which edits the registry. I always must right-click and run it as administrator. Then it will ask, if I want to allow the program to make changes on my computer. I want the file to ask this question automatically when I open it. Is there any way to do it? Or any other way(e.g. iexpress)?

Thank you for the answers, Andrew


This can be done:

  • via a shortcut:
    1. Create a shortcut for the .bat file → Right-click shortcut → Properties
    2. Tab: ShortcutAdvancedRun as Administrator → OK

  • from code within the script using ShellExecute: (explanation)
    How do you run a command as an administrator from the Windows command line?
    @if (1==1) @if(1==0) @ELSE
      @echo off&SETLOCAL ENABLEEXTENSIONS
    
      >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"||(
        cscript //E:JScript //nologo "%~f0"
        @goto :EOF
      )
    
      echo.Performing admin tasks...
        :: # call foo.exe
    
      @goto :EOF
    
    @end @ELSE
      ShA=new ActiveXObject("Shell.Application")
      ShA.ShellExecute("cmd.exe","/c \""+WScript.ScriptFullName+"\"","","runas",5);
    
    @end