@ECHO OFF&(PUSHD "%~DP0")&(REG QUERY "HKU\S-1-5-19">NUL 2>&1)||(
powershell -Command "Start-Process '%~sdpnx0' -Verb RunAs"&&EXIT)



:MENU
ECHO.&ECHO 1、添加系统右键 EmEditor 查找项
ECHO.&ECHO 2、移除系统右键 EmEditor 查找项
IF EXIST "%WinDir%\System32\CHOICE.exe" CHOICE /C 12 /N >NUL 2>NUL
IF EXIST "%WinDir%\System32\CHOICE.exe" IF "%ERRORLEVEL%"=="2" GOTO RemoveMenu
IF EXIST "%WinDir%\System32\CHOICE.exe" IF "%ERRORLEVEL%"=="1" GOTO AddMenu
IF NOT EXIST "%WinDir%\System32\CHOICE.exe" ECHO.&SET /p choice=输入数字项敲回车键：
IF NOT EXIST "%WinDir%\System32\CHOICE.exe" IF NOT "%choice%"=="" SET choice=%choice:~0,1%
IF NOT EXIST "%WinDir%\System32\CHOICE.exe" IF /I "%choice%"=="1" GOTO AddMenu
IF NOT EXIST "%WinDir%\System32\CHOICE.exe" IF /I "%choice%"=="2" GOTO RemoveMenu
IF NOT EXIST "%WinDir%\System32\CHOICE.exe" ECHO.&ECHO 输入无效 &PAUSE&CLS&GOTO MENU

:AddMenu
@REM 添加空白处右键菜单
reg add HKCR\Directory\Background\shell\EmEditor /t REG_SZ /d "用 EmEditor 在文件中查找" /f >NUL 2>NUL
reg add HKCR\Directory\Background\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCR\Directory\Background\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" /fd %V" /f >NUL 2>NUL
 
reg add HKCU\SOFTWARE\Classes\Directory\Background\shell\EmEditor /t REG_SZ /d "用 EmEditor 在文件中查找" /f >NUL 2>NUL
reg add HKCU\SOFTWARE\Classes\Directory\Background\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCU\SOFTWARE\Classes\Directory\Background\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" /fd %V" /f >NUL 2>NUL
 
@REM 添加目录右键菜单
reg add HKCR\Directory\Directory\shell\EmEditor /t REG_SZ /d "用 EmEditor 在文件中查找" /f >NUL 2>NUL
reg add HKCR\Directory\Directory\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCR\Directory\Directory\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" /fd %%1" /f >NUL 2>NUL
 
reg add HKCU\SOFTWARE\Classes\Directory\shell\EmEditor /t REG_SZ /d "用 EmEditor 在文件中查找" /f >NUL 2>NUL
reg add HKCU\SOFTWARE\Classes\Directory\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCU\SOFTWARE\Classes\Directory\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" /fd %%1" /f >NUL 2>NUL
 
@REM 添加盘符右键菜单
reg add HKCR\Drive\shell\EmEditor /t REG_SZ /d "用 EmEditor 在文件中查找" /f >NUL 2>NUL
reg add HKCR\Drive\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCR\Drive\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" /fd %V" /f >NUL 2>NUL
 
reg add HKCU\SOFTWARE\Classes\Drive\shell\EmEditor /t REG_SZ /d "用 EmEditor 在文件中查找" /f >NUL 2>NUL
reg add HKCU\SOFTWARE\Classes\Drive\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCU\SOFTWARE\Classes\Drive\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" /fd %V" /f >NUL 2>NUL
 
@REM 添加文件右键菜单
reg add HKCR\*\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCR\*\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" \"%%1\"" /f >NUL 2>NUL
 
reg add HKCR\SOFTWARE\Classes\*\shell\EmEditor /v "Icon" /t REG_SZ /d "%~dp0emedres.dll,-128" /f >NUL 2>NUL
reg add HKCR\SOFTWARE\Classes\*\shell\EmEditor\command /t REG_SZ /d "\"%~dp0emeditor.exe\" \"%%1\"" /f >NUL 2>NUL


ECHO.&ECHO 添加完成, 任意键返回!
PAUSE>NUL&CLS&GOTO MENU

:RemoveMenu
@REM 删除空白处右键菜单
reg delete "HKCR\Directory\Background\shell\EmEditor" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\Directory\Background\shell\EmEditor" /f >NUL 2>NUL
 
@REM 删除目录右键菜单
reg delete "HKCR\Directory\Directory\shell\EmEditor" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\Directory\shell\EmEditor" /f >NUL 2>NUL
 
@REM 删除盘符右键菜单
reg delete "HKCR\Drive\shell\EmEditor" /f >NUL 2>NUL
reg delete "HKCU\SOFTWARE\Classes\Drive\shell\EmEditor" /f >NUL 2>NUL
 
@REM 删除文件夹右键菜单
reg delete "HKCR\*\shell\EmEditor" /f >NUL 2>NUL
reg delete "HKCR\SOFTWARE\Classes\*\shell\EmEditor" /f >NUL 2>NUL

ECHO.&ECHO 删除完成, 任意键返回!
PAUSE>NUL&CLS&GOTO MENU