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

后端 未结 15 950
陌清茗
陌清茗 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

    You can have the script call itself with psexec's -h option to run elevated.

    I'm not sure how you would detect if it's already running as elevated or not... maybe re-try with elevated perms only if there's an Access Denied error?

    Or, you could simply have the commands for the xcopy and reg.exe always be run with psexec -h, but it would be annoying for the end-user if they need to input their password each time (or insecure if you included the password in the script)...

提交回复
热议问题