1. 程式人生 > >windows下將cmd新增至右鍵指令碼

windows下將cmd新增至右鍵指令碼

@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 "\<%ch%\>">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.