Skip to content

Instantly share code, notes, and snippets.

@cpuwolf
Last active September 23, 2023 22:13
Show Gist options
  • Save cpuwolf/150920f87259c46fb9f318c61f294c3a to your computer and use it in GitHub Desktop.
Save cpuwolf/150920f87259c46fb9f318c61f294c3a to your computer and use it in GitHub Desktop.
run power shell script from batch file
::written by cpuwolf@gmail.com 2023 Sep.
::
::must run as administrator
@chcp 437 >nul 2>&1
:: Add value for UAC shield icon:
REG ADD "HKCR\Microsoft.PowerShellScript.1\Shell\runas" /v HasLUAShield /t REG_SZ /d "" /f
:: Add value to create context menu item:
REG ADD "HKCR\Microsoft.PowerShellScript.1\Shell\runas\command" /ve /t REG_EXPAND_SZ /d "\"%%SYSTEMROOT%%\System32\WindowsPowerShell\v1.0\powershell.exe\" -executionpolicy bypass -nologo -file \"%%1\"" /f
@cd /d "%~dp0"
@NET SESSION >nul 2>&1
@IF %ERRORLEVEL% EQU 0 (
@powershell.exe -ExecutionPolicy bypass -File %~dp0qmdevfw.ps1
) ELSE (
@ECHO Error! Please run as administrator!
pause
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment