-
Notifications
You must be signed in to change notification settings - Fork 1
/
handle_add_to_context_menu.bat
81 lines (73 loc) · 2.49 KB
/
handle_add_to_context_menu.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@echo off
@rem HKLM=HKEY_LOCAL_MACHINE
@rem HKCU=HKEY_CURRENT_USER
if "%1"=="" (
echo No file specified.
pause
exit /b
)
set filePath=%1
set fileName=%~nx1
set fileDir=%~dp1
call :HandleAddToContextMenuOnFlie "%fileDir%"
call :HandleFileName %filePath%
pause
goto :eof
:HandleAddToContextMenuOnFlie
setlocal EnableDelayedExpansion
:: add filepath to regedit.
set FilePath=%~1
set FileName=%~n1
call :color_text 2f "+++++++++++++HandleAddToContextMenuOnFlie+++++++++++++++"
echo FilePath:%FilePath%
echo FileName:%FileName%
REG QUERY "HKCR\*\shell\%FileName%" >nul 2>&1
if %errorlevel%==0 (
call :color_text 6f "-------------'Current Menu' option already exists---------------"
) else (
REG ADD "HKCR\*\shell\%FileName%" /ve /d "%FileName%" /f
echo REG ADD "HKCR\*\shell\%FileName%" /ve /d "%FileName%" /f
REG ADD "HKCR\*\shell\%FileName%" /v "icon" /t REG_SZ /d "%FilePath%" /f
echo REG ADD "HKCR\*\shell\%FileName%" /v "icon" /t REG_SZ /d "%FilePath%" /f
REG ADD "HKCR\*\shell\%FileName%\command" /ve /d "\"%FilePath%\" \"%%1\"" /f
echo REG ADD "HKCR\*\shell\%FileName%\command" /ve /d "\"%FilePath%\" \"%%1\"" /f
call :color_text 2f "-------------'Current Menu' option added succ.---------------"
)
echo REG QUERY "HKCR\*\shell\%FileName%"
endlocal
goto :eof
:QuerySystemEnv
setlocal EnableDelayedExpansion
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
reg query "HKEY_CURRENT_USER\Environment"
endlocal
goto :eof
@rem YellowBackground 6f ef
@rem BlueBackground 9f bf 3f
@rem GreenBackground af 2f
@rem RedBackground 4f cf
@rem GreyBackground 7f 8f
@rem PurpleBackground 5f
:color_text
setlocal EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
endlocal
echo .
goto :eof
:HandleFileName
setlocal EnableDelayedExpansion
set myfile=%1
set mypath=%~dp1
set myname=%~n1
set myext=%~x1
call :color_text 2f "++++++++++++++++++ get_path_by_file ++++++++++++++++++++++++"
echo !mypath! !myname! !myext!
call :color_text 2f "-------------------- get_path_by_file -----------------------"
endlocal & set %~2=%mypath%&set %~3=%myname%&set %~4=%myext%
goto :eof