1

(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

1 Answer 1

1

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
    
1
  • @Andrew in case you'd like to do so without creating a shortcut, I added links and quoted info on how to do so directly within the script itself.
    – JW0914
    Jul 4, 2021 at 11:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .