Skip to content

Instantly share code, notes, and snippets.

@NullPointerMaker
Last active March 14, 2021 16:29
Show Gist options
  • Save NullPointerMaker/880ff9242203ade6b51104ff8314ce95 to your computer and use it in GitHub Desktop.
Save NullPointerMaker/880ff9242203ade6b51104ff8314ce95 to your computer and use it in GitHub Desktop.
PowerShell Launcher
@Echo Off
Rem PS1 script launcher
Rem PS1 file can not exec directly so need launcher
Rem Use parameter Minimized to start in minimized window mode
Rem Use parameter Hidden to start in hidden window mode
Rem The other parameters will be passed to the PS1 script
SetLocal EnableDelayedExpansion
Title %~n0
CD /D "%~dp0"
Set Path=!Path!;!SystemRoot!\System32\WindowsPowerShell\v1.0\
If /I "%1"=="Minimized" (
Shift /1
PowerShell -ExecutionPolicy Unrestricted -NoProfile -WindowStyle Minimized -File %~dpn0.ps1 %*
Set ExitCode=!ErrorLevel!
If Not "!ExitCode!"=="0" (
Echo.
Echo Exit Code: !ExitCode! 1>&2
Echo.
Pause
)
) Else If /I "%1"=="Hidden" (
Shift /1
PowerShell -ExecutionPolicy Unrestricted -NoProfile -WindowStyle Hidden -File %~dpn0.ps1 %*
Set ExitCode=!ErrorLevel!
If Not "!ExitCode!"=="0" (
Echo.
Echo Exit Code: !ExitCode! 1>&2
)
) Else (
PowerShell -ExecutionPolicy Unrestricted -NoProfile -File %~dpn0.ps1 %*
Set ExitCode=!ErrorLevel!
Echo.
Pause
)
Exit !ExitCode!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment