How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?

后端 未结 15 1204
陌清茗
陌清茗 2020-11-22 03:59

I want my batch file to only run elevated. If not elevated, provide an option for the user to relaunch batch as elevated.

I\'m writing a batch file to set a system v

15条回答
  •  清歌不尽
    2020-11-22 04:38

    Following solution is clean and works perfectly.

    1. Download Elevate zip file from https://www.winability.com/download/Elevate.zip

    2. Inside zip you should find two files: Elevate.exe and Elevate64.exe. (The latter is a native 64-bit compilation, if you require that, although the regular 32-bit version, Elevate.exe, should work fine with both the 32- and 64-bit versions of Windows)

    3. Copy the file Elevate.exe into a folder where Windows can always find it (such as C:/Windows). Or you better you can copy in same folder where you are planning to keep your bat file.

    4. To use it in a batch file, just prepend the command you want to execute as administrator with the elevate command, like this:

     elevate net start service ...
    

提交回复
热议问题