@echo off
SetLocal EnableDelayedExpansion
title Add Cmd to Promot Menu
net session >nul 2>&1
if not "%errorLevel%" == "0" (
echo Oops: This tools must run with administrator permissions!
echo it will popup the UAC dialog, please click [Yes] to continue.
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /b 2
)
REM 还有点问题,%V进不去
@echo ***********************************
@echo * 1: 目录上右键打开CMD *
@echo * 2: 空白处右键打开CMD *
@echo * 3: 盘符上右键打开CMD *
@echo * 4: 空白处以管理员权限打开CMD *
@echo ***********************************
echo.
set /p ch=please input your choose(1/2/3/4):
if %ch%=="" echo You input is null&goto :EOF
set case=1,2,3,4 >nul
echo %case%|findstr "\">nul&if errorlevel 1 goto :err
goto set_%ch%
goto err
:set_1
rem 目录上右键打开CMD
echo Modify Registry ……
reg add "HKLM\SOFTWARE\Classes\Folder\shell\CommandPrompt" /ve /d "在此处打开命令提示符"
reg add "HKLM\SOFTWARE\Classes\Folder\shell\CommandPrompt" /v Icon /t REG_SZ /d "cmd.exe"
reg add "HKLM\SOFTWARE\Classes\Folder\shell\CommandPrompt\command" /ve /d "cmd.exe /s /k pushd \"%%V\""
goto :Done
:set_2
rem 空白处右键打开CMD
reg add "HKCR\Directory\Background\shell\OpenCmd" /ve /d "在此处打开命令提示符"
reg add "HKCR\Directory\Background\shell\OpenCmd" /v Icon /t REG_SZ /d "cmd.exe"
reg add "HKCR\Directory\Background\shell\OpenCmd\command" /ve /d "cmd.exe /s /k pushd \"%%V\""
goto :Done
:set_3
rem 盘符上右键打开CMD
reg add "HKCR\Drive\shell\OpenCmd" /ve /d "在此处打开命令提示符"
reg add "HKCR\Drive\shell\OpenCmd" /v Icon /t REG_SZ /d "cmd.exe"
reg add "HKCR\Drive\shell\OpenCmd\command" /ve /d "cmd.exe /s /k pushd \"%%V\""
goto :Done
:set_4
rem 空白处以管理员权限打开CMD
reg add "HKCR\Directory\Background\shell\runas" /ve /d "以管理员身份打开命令提示符"
reg add "HKCR\Directory\Background\shell\runas" /v HasLUAShield /t REG_SZ /d ""
reg add "HKCR\Directory\Background\shell\runas\command" /ve /d "cmd.exe /s /k pushd \"%%V\""
goto :Done
:err
goto :EOF
:: error
:Done
if exist "%temp%\getadmin.vbs" (del "%temp%\getadmin.vbs" /f /q)
goto :EOF
echo Done.
echo.