Last active
December 17, 2025 12:17
-
-
Save tnhung2011/1e6b1a945a018e3dd2c13e5841530bca to your computer and use it in GitHub Desktop.
Run a program as invoker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| setlocal enableextensions enabledelayedexpansion | |
| if "%~1"=="/?" goto help | |
| set args=%* | |
| set prefix= | |
| if "%~1"=="/nowait" ( | |
| ::%* strips spaces | |
| set args=!args:~7! | |
| set prefix=start "" | |
| shift | |
| ) | |
| set foropt=tokens^^=*^^ eol^^= | |
| ::searches for executable on PATH and current directory | |
| ::custom implementation as where.exe is not available on older systems | |
| ::https://superuser.com/a/49155 | |
| if "%~x1"=="" ( | |
| set "for1=for %%e in (%PATHEXT%) do for /f %foropt% %%a in ("%~1%%e") do" | |
| ) else ( | |
| set "for1=for /f %foropt% %%a in ("%~1") do" | |
| ) | |
| set PATH=.;%PATH% | |
| %for1% if not "%%~$PATH:a"=="" goto break | |
| >&2 echo ERROR: File not found: %1 | |
| exit /b -1 | |
| :break | |
| if not defined __COMPAT_LAYER goto setCompatLayer | |
| if "!__COMPAT_LAYER!"=="!__COMPAT_LAYER:RunAsInvoker=!" ( | |
| :setCompatLayer | |
| for /f %foropt% %%a in ("!__COMPAT_LAYER! RunAsInvoker") do set __COMPAT_LAYER=%%a | |
| ) | |
| echo __COMPAT_LAYER=!__COMPAT_LAYER! | |
| for /f %foropt% %%a in ("!args!") do !prefix!%%a | |
| exit /b | |
| :help | |
| for /f %%A in ('prompt $H ^&echo on ^&for %%B in ^(1^) do rem') do set bs=%%A | |
| echo Run a program as invoker (unprivileged^). | |
| echo UAC prompts will not be displayed. | |
| echo: | |
| echo ASINVOKER [/nowait] program [parameters] | |
| echo: | |
| echo %bs% /nowait Do not wait for the program to terminate. | |
| echo %bs% This will spawn a new window. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment