标题: [系统相关] [已解决]请问这个批处理还能精简下吗 [打印本页]
作者: kli2018 时间: 2020-7-2 09:38 标题: [已解决]请问这个批处理还能精简下吗
本帖最后由 kli2018 于 2020-7-2 13:28 编辑
如题- @echo off
- PUSHD %~dp0
-
- echo.
- echo 1.为常用图片格式文件添加右键打开
- echo.
- echo 2.删除
- echo.
- set /p file=请选择?(1/2):
- if "%file%"=="1" goto ql1
- if "%file%"=="2" goto ql2
-
- :ql1
- for /f "tokens=2 delims==" %%a in ('assoc .bmp') do set "pictype=%%a"
- call :addright
- for /f "tokens=2 delims==" %%a in ('assoc .gif') do set "pictype=%%a"
- call :addright
- for /f "tokens=2 delims==" %%a in ('assoc .ico') do set "pictype=%%a"
- call :addright
- for /f "tokens=2 delims==" %%a in ('assoc .jpg') do set "pictype=%%a"
- call :addright
- for /f "tokens=2 delims==" %%a in ('assoc .jpe') do set "pictype=%%a"
- call :addright
- for /f "tokens=2 delims==" %%a in ('assoc .jpeg') do set "pictype=%%a"
- call :addright
- for /f "tokens=2 delims==" %%a in ('assoc .png') do set "pictype=%%a"
- call :addright
- goto :EOF
-
- :ql2
- for /f "tokens=2 delims==" %%a in ('assoc .bmp') do set "pictype1=%%a"
- call :deleteright
- for /f "tokens=2 delims==" %%a in ('assoc .gif') do set "pictype1=%%a"
- call :deleteright
- for /f "tokens=2 delims==" %%a in ('assoc .ico') do set "pictype1=%%a"
- call :deleteright
- for /f "tokens=2 delims==" %%a in ('assoc .jpg') do set "pictype1=%%a"
- call :deleteright
- for /f "tokens=2 delims==" %%a in ('assoc .jpe') do set "pictype1=%%a"
- call :deleteright
- for /f "tokens=2 delims==" %%a in ('assoc .jpeg') do set "pictype1=%%a"
- call :deleteright
- for /f "tokens=2 delims==" %%a in ('assoc .png') do set "pictype1=%%a"
- call :deleteright
- goto :EOF
-
- :addright
- Reg.exe add "HKLM\SOFTWARE\Classes\%pictype%\shell\open1" /v "Icon" /t REG_SZ /d "%CD%\FSViewer.exe,0" /f
- Reg.exe add "HKLM\SOFTWARE\Classes\%pictype%\shell\open1" /ve /t REG_SZ /d "FSViewer" /f
- Reg.exe add "HKLM\SOFTWARE\Classes\%pictype%\shell\open1\command" /ve /t REG_SZ /d "\"%CD%\FSViewer.exe\" \"%%1\"" /f
- goto :EOF
-
- :deleteright
- Reg.exe delete "HKLM\SOFTWARE\Classes\%pictype1%\shell\open1" /f
- goto :EOF
复制代码
作者: went 时间: 2020-7-2 12:07
- @echo off
- PUSHD %~dp0
-
- echo.
- echo 1.为常用图片格式文件添加右键打开
- echo.
- echo 2.删除
- echo.
- set /p file=请选择?(1/2):
- set "ext=.bmp .gif .ico .jpg .jpe .jpeg .png"
- if "%file%"=="1" for /f "tokens=2 delims==" %%a in ('assoc ^| findstr "%ext%"') do call :addright "%%a"
- if "%file%"=="2" for /f "tokens=2 delims==" %%a in ('assoc ^| findstr "%ext%"') do call :deleteright "%%a"
- pause&exit
-
- :addright
- Reg.exe add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /v "Icon" /t REG_SZ /d "%CD%\FSViewer.exe,0" /f
- Reg.exe add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /ve /t REG_SZ /d "FSViewer" /f
- Reg.exe add "HKLM\SOFTWARE\Classes\%~1\shell\open1\command" /ve /t REG_SZ /d "\"%CD%\FSViewer.exe\" \"%%1\"" /f
- goto :EOF
- :deleteright
- Reg.exe delete "HKLM\SOFTWARE\Classes\%~1\shell\open1" /f
- goto :EOF
复制代码
作者: kli2018 时间: 2020-7-2 13:28
本帖最后由 kli2018 于 2020-7-2 13:54 编辑
回复 2# went
谢谢
同时再问个问题
为什么我只是
set "ext=.doc .docx"
但是最后.mydocs这个的下面也添加了啊?
作者: smss 时间: 2020-7-2 14:15
本帖最后由 smss 于 2020-7-2 14:36 编辑
- @Echo off
- :X
- cls&echo 1.添加图片格式关联 2.删除图片格式关联&choice /C:12 /N /M ">>输入选择:
- for /f "tokens=2 delims==" %%i in ('assoc ^|findstr ".bmp .gif .ico .jpg .jpe .jpeg .png"') do call :%errorlevel% "%%i"
- ping 0 -n "2">nul&goto :X
- :1
- reg add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /v "Icon" /t REG_SZ /d "%CD%\FSViewer.exe,0" /f
- reg add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /ve /t REG_SZ /d "FSViewer" /f
- reg add "HKLM\SOFTWARE\Classes\%~1\shell\open1\command" /ve /t REG_SZ /d "\"%CD%\FSViewer.exe\" \"%%1\"" /f
- goto :EOF
- :2
- reg delete "HKLM\SOFTWARE\Classes\%~1\shell\open1" /f
- goto :EOF
复制代码
作者: went 时间: 2020-7-2 14:17
回复 3# kli2018
改成这样复制代码
更加准确就复制代码
作者: kli2018 时间: 2020-7-2 15:35
回复 4# smss
谢谢
作者: kli2018 时间: 2020-7-2 15:35
回复 5# went
谢谢
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |