Last active
May 20, 2022 20:26
-
-
Save Jj0YzL5nvJ/ea0ee306efa0583a9a2a04893d7640b3 to your computer and use it in GitHub Desktop.
Life hack for Windows CLI users
This file contains 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 | |
cls | |
for /f "tokens=2 delims=[]" %%a in ('ver') do set wv=%%a | |
for /f "tokens=2 delims=. " %%a in ('echo %wv%') do set wv=%%a | |
net session>nul 2>&1 | |
if errorlevel 1 ( | |
if %wv% LEQ 5 (goto a1) else goto a2) | |
reg add HKCR\Directory\shell\CommandPrompt /ve /d "Open with Command Prompt" /f>nul 2>&1 | |
reg add HKCR\Directory\shell\CommandPrompt\command /ve /d "%ComSpec% /k pushd \"%%1\" && title Command Prompt" /f>nul 2>&1 | |
reg add HKCR\Drive\shell\CommandPrompt /ve /d "Open with Command Prompt" /f>nul 2>&1 | |
reg add HKCR\Drive\shell\CommandPrompt\command /ve /d "%ComSpec% /k pushd \"%%1\" && title Command Prompt" /f>nul 2>&1 | |
if %wv% LEQ 5 exit /b 0 | |
reg add HKCR\Directory\shell\CommandPrompt /v Icon /t REG_EXPAND_SZ /d "%%ComSpec%%,0" /f>nul 2>&1 | |
reg add HKCR\Drive\shell\CommandPrompt /v Icon /t REG_EXPAND_SZ /d "%%ComSpec%%,0" /f>nul 2>&1 | |
reg add HKCR\Directory\Background\shell\CommandPrompt /ve /d "Open Command Prompt here" /f>nul 2>&1 | |
reg add HKCR\Directory\Background\shell\CommandPrompt /v Icon /t REG_EXPAND_SZ /d "%%ComSpec%%,0" /f>nul 2>&1 | |
reg add HKCR\Directory\Background\shell\CommandPrompt\command /ve /d "%ComSpec% /k title Command Prompt" /f>nul 2>&1 | |
reg add HKCR\DesktopBackground\shell\CommandPrompt /ve /d "Open Command Prompt here" /f>nul 2>&1 | |
reg add HKCR\DesktopBackground\shell\CommandPrompt /v Icon /t REG_EXPAND_SZ /d "%%ComSpec%%,0" /f>nul 2>&1 | |
reg add HKCR\DesktopBackground\shell\CommandPrompt\command /ve /d "%ComSpec% /k title Command Prompt" /f>nul 2>&1 | |
exit /b 0 | |
:a1 | |
cls | |
set US=support | |
set /p US=^User: | |
runas /user:"%US%" "%~f0" | |
if errorlevel 1 goto a1 | |
exit | |
:a2 | |
echo Set UAC = CreateObject("Shell.Application")>"%TEMP%\uac.vbs" | |
echo UAC.ShellExecute WScript.Arguments.Item(0), "", "", "runas", ^1>>"%TEMP%\uac.vbs" | |
cscript //nologo "%TEMP%\uac.vbs" "%~f0" | |
ping 127.0.0.1 -n 3 >nul | |
del /f /q "%TEMP%\uac.vbs" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment