@Echo off
pushd "%~dp0"
Set CurPath=%~dp0
Set CurFile=%~nx0
Set CurFile=%CurPath%%CurFile%
Set EWS_DIR=%CurPath:~0,-1%
Set EWS_KEY=EasyWinSetup{dc9e332c-abe0-453a-8d2b-4f1530f4a9bc}
Set EWS_CONTEXT=EasyWinSetup 으로 열기
Set "Position=-"
Set DelMODE=0
Set REGRT=HKLM\SOFTWARE\Classes

REM Admin
:ChkAdmin
Set sAdmin=관리자 권한 필요
Reg.exe query "HKU\S-1-5-19\Environment" > nul
IF NOT ERRORLEVEL 1 Set "sAdmin=Administrator mode" & GOTO :SETFILENAME

:GetAdmin
@setlocal enabledelayedexpansion
Echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\admin.vbs"
Echo UAC.ShellExecute "%CurFile%", "", "", "runas", 1 >> "%temp%\admin.vbs"
wscript.exe "%temp%\admin.vbs"
del "%temp%\admin.vbs"
EXIT

:SETFILENAME
rem %PROCESSOR_ARCHITECTURE%
rem AMD64
rem x86
Set EWS_FNAME=EWS_x86.exe
IF /i "%PROCESSOR_ARCHITECTURE%" equ "AMD64" Set EWS_FNAME=EWS_x64.exe
Set Tpath=%EWS_DIR%\%EWS_FNAME%
IF EXIST "%Tpath%" GOTO :MAINMENU
Echo EasyWinSetup 실행 파일이 없습니다.
Pause
GOTO :END

:GetInfo
Set TpathDBS=%Tpath:\=\\%
FOR /F "tokens=2 delims==" %%a in ('wmic datafile where name^="%TpathDBS%" get filename /value') do Set fname=%%a
FOR /F "tokens=2 delims==" %%a in ('wmic datafile where name^="%TpathDBS%" get Version /value') do Set Vers=%%a

:MAINMENU
CLS
Echo.
Echo   -----------------------------------------------------------------
Echo.  %sAdmin%
REM Echo.  %fname% %Vers%
Echo.  %Tpath%
Echo   -----------------------------------------------------------------
Echo.  WIM SWM ESD 확장자 문맥 메뉴에 등록. v0.7.1.0 이상.
Echo   -----------------------------------------------------------------
Echo.  [T] - '%EWS_CONTEXT%' 등록
Echo.  [B] - '%EWS_CONTEXT%' 하단에 등록
Echo.  [E] - 문맥 메뉴에서 제거
Echo.  [P] - 문맥 메뉴에서 완전 제거
Echo.  [X] - Exit
Echo   -----------------------------------------------------------------
Set INPUT=
Set /P INPUT=Select : 
::
IF /i '%INPUT%'=='T' Set "Position=-" & GOTO :REGMAIN
IF /i '%INPUT%'=='B' Set "Position=Bottom" & GOTO :REGMAIN
IF /i '%INPUT%'=='E' Set "DelMODE=0" & GOTO :UNREGMAIN
IF /i '%INPUT%'=='P' Set "DelMODE=1" & GOTO :UNREGMAIN
IF /i '%INPUT%'=='X' GOTO :END
Echo.

:RETMENU
Echo.
Echo Press Any Key To MAINMENU...
PAUSE >NUL
GOTO :MAINMENU

REM HKEY_CURRENT_USER\SOFTWARE\Classes
REM HKEY_LOCAL_MACHINE\SOFTWARE\Classes
REM HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations
:REGMAIN
CALL :EWSREG wim
CALL :EWSREG swm
CALL :EWSREG esd
rem CALL :EWSREG iso
GOTO :RETMENU

:EWSREG
REM Top, Bottom, -
REM Reg.exe add "%REGRT%\.%1\shell\%EWS_KEY%" /v "CommandFlags" /t REG_DWORD /d "0x10" /f
REM Reg.exe add "%REGRT%\.%1\shell\%EWS_KEY%" /v "Position" /t REG_SZ /d "%Position%" /f
REM Reg.exe add "%REGRT%\.%1\shell\%EWS_KEY%" /v "Icon" /t REG_SZ /d "\"%Tpath%\"" /f
REM Reg.exe add "%REGRT%\.%1\shell\%EWS_KEY%" /v "MUIVerb" /t REG_SZ /d "%EWS_CONTEXT%" /f
REM Reg.exe add "%REGRT%\.%1\shell\%EWS_KEY%\command" /ve /t REG_SZ /d "\"%Tpath%\" /ImageFile:\"%%1\"" /f

Reg.exe add "%REGRT%\SystemFileAssociations\.%1\shell\%EWS_KEY%" /v "CommandFlags" /t REG_DWORD /d "0x10" /f
Reg.exe add "%REGRT%\SystemFileAssociations\.%1\shell\%EWS_KEY%" /v "Position" /t REG_SZ /d "%Position%" /f
Reg.exe add "%REGRT%\SystemFileAssociations\.%1\shell\%EWS_KEY%" /v "Icon" /t REG_SZ /d "\"%Tpath%\"" /f
Reg.exe add "%REGRT%\SystemFileAssociations\.%1\shell\%EWS_KEY%" /v "MUIVerb" /t REG_SZ /d "%EWS_CONTEXT%" /f
Reg.exe add "%REGRT%\SystemFileAssociations\.%1\shell\%EWS_KEY%\Command" /ve /t REG_SZ /d "\"%Tpath%\" /ImageFile:\"%%1\"" /f
EXIT /B

:UNREGMAIN
CALL :EWSUNREG wim
CALL :EWSUNREG swm
CALL :EWSUNREG esd
rem CALL :EWSUNREG iso
GOTO :RETMENU

:EWSUNREG
rem Reg.exe delete "%REGRT%\.%1\Shell" /f
IF "%DelMODE%" equ "0" Reg.exe delete "%REGRT%\SystemFileAssociations\.%1\shell\%EWS_KEY%" /f
IF "%DelMODE%" equ "1" Reg.exe delete "%REGRT%\SystemFileAssociations\.%1" /f
EXIT /B

:END
POPD
EXIT