Skip to content

Instantly share code, notes, and snippets.

@Dadangdut33
Last active August 11, 2024 17:44
Show Gist options
  • Save Dadangdut33/015d245f96303d43fb859bcd3379eda2 to your computer and use it in GitHub Desktop.
Save Dadangdut33/015d245f96303d43fb859bcd3379eda2 to your computer and use it in GitHub Desktop.
A simple bat script to run thing as admin
@echo off
if "%1"=="runas" (
cd %~dp0
start "" "full_path_of.exe"
) else (
powershell Start -File "cmd '/K %~f0 runas'" -Verb RunAs
)
exit
@Dadangdut33
Copy link
Author

Dadangdut33 commented Aug 11, 2024

Explanation:

  • %1 First input argument assigned to BAT file.
  • %~f0 expands to full path to the executed BAT file
  • %~dp0 expands to full directory path from where the BAT file is executed

Source bat script: https://stackoverflow.com/a/69794302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment