[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] [已解决]请问这个批处理还能精简下吗

本帖最后由 kli2018 于 2020-7-2 13:28 编辑

如题
  1. @echo off
  2. PUSHD %~dp0
  3. echo.
  4. echo 1.为常用图片格式文件添加右键打开
  5. echo.
  6. echo 2.删除
  7. echo.
  8. set /p file=请选择?(1/2):
  9. if "%file%"=="1" goto ql1
  10. if "%file%"=="2" goto ql2
  11. :ql1
  12. for /f "tokens=2 delims==" %%a in ('assoc .bmp') do set "pictype=%%a"
  13. call :addright
  14. for /f "tokens=2 delims==" %%a in ('assoc .gif') do set "pictype=%%a"
  15. call :addright
  16. for /f "tokens=2 delims==" %%a in ('assoc .ico') do set "pictype=%%a"
  17. call :addright
  18. for /f "tokens=2 delims==" %%a in ('assoc .jpg') do set "pictype=%%a"
  19. call :addright
  20. for /f "tokens=2 delims==" %%a in ('assoc .jpe') do set "pictype=%%a"
  21. call :addright
  22. for /f "tokens=2 delims==" %%a in ('assoc .jpeg') do set "pictype=%%a"
  23. call :addright
  24. for /f "tokens=2 delims==" %%a in ('assoc .png') do set "pictype=%%a"
  25. call :addright
  26. goto :EOF
  27. :ql2
  28. for /f "tokens=2 delims==" %%a in ('assoc .bmp') do set "pictype1=%%a"
  29. call :deleteright
  30. for /f "tokens=2 delims==" %%a in ('assoc .gif') do set "pictype1=%%a"
  31. call :deleteright
  32. for /f "tokens=2 delims==" %%a in ('assoc .ico') do set "pictype1=%%a"
  33. call :deleteright
  34. for /f "tokens=2 delims==" %%a in ('assoc .jpg') do set "pictype1=%%a"
  35. call :deleteright
  36. for /f "tokens=2 delims==" %%a in ('assoc .jpe') do set "pictype1=%%a"
  37. call :deleteright
  38. for /f "tokens=2 delims==" %%a in ('assoc .jpeg') do set "pictype1=%%a"
  39. call :deleteright
  40. for /f "tokens=2 delims==" %%a in ('assoc .png') do set "pictype1=%%a"
  41. call :deleteright
  42. goto :EOF
  43. :addright
  44. Reg.exe add "HKLM\SOFTWARE\Classes\%pictype%\shell\open1" /v "Icon" /t REG_SZ /d "%CD%\FSViewer.exe,0" /f
  45. Reg.exe add "HKLM\SOFTWARE\Classes\%pictype%\shell\open1" /ve /t REG_SZ /d "FSViewer" /f
  46. Reg.exe add "HKLM\SOFTWARE\Classes\%pictype%\shell\open1\command" /ve /t REG_SZ /d "\"%CD%\FSViewer.exe\" \"%%1\"" /f
  47. goto :EOF
  48. :deleteright
  49. Reg.exe delete "HKLM\SOFTWARE\Classes\%pictype1%\shell\open1" /f
  50. goto :EOF
复制代码

  1. @echo off
  2. PUSHD %~dp0
  3. echo.
  4. echo 1.为常用图片格式文件添加右键打开
  5. echo.
  6. echo 2.删除
  7. echo.
  8. set /p file=请选择?(1/2):
  9. set "ext=.bmp .gif .ico .jpg .jpe .jpeg .png"
  10. if "%file%"=="1" for /f "tokens=2 delims==" %%a in ('assoc ^| findstr "%ext%"') do call :addright "%%a"
  11. if "%file%"=="2" for /f "tokens=2 delims==" %%a in ('assoc ^| findstr "%ext%"') do call :deleteright "%%a"
  12. pause&exit
  13. :addright
  14. Reg.exe add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /v "Icon" /t REG_SZ /d "%CD%\FSViewer.exe,0" /f
  15. Reg.exe add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /ve /t REG_SZ /d "FSViewer" /f
  16. Reg.exe add "HKLM\SOFTWARE\Classes\%~1\shell\open1\command" /ve /t REG_SZ /d "\"%CD%\FSViewer.exe\" \"%%1\"" /f
  17. goto :EOF
  18. :deleteright
  19. Reg.exe delete "HKLM\SOFTWARE\Classes\%~1\shell\open1" /f
  20. goto :EOF
复制代码

TOP

本帖最后由 kli2018 于 2020-7-2 13:54 编辑

回复 2# went

谢谢

同时再问个问题
为什么我只是

set "ext=.doc .docx"

但是最后.mydocs这个的下面也添加了啊?

TOP

本帖最后由 smss 于 2020-7-2 14:36 编辑
  1. @Echo off
  2. :X
  3. cls&echo 1.添加图片格式关联  2.删除图片格式关联&choice /C:12 /N /M ">>输入选择:
  4. for /f "tokens=2 delims==" %%i in ('assoc ^|findstr ".bmp .gif .ico .jpg .jpe .jpeg .png"') do call :%errorlevel% "%%i"
  5. ping 0 -n "2">nul&goto :X
  6. :1
  7. reg add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /v "Icon" /t REG_SZ /d "%CD%\FSViewer.exe,0" /f
  8. reg add "HKLM\SOFTWARE\Classes\%~1\shell\open1" /ve /t REG_SZ /d "FSViewer" /f
  9. reg add "HKLM\SOFTWARE\Classes\%~1\shell\open1\command" /ve /t REG_SZ /d "\"%CD%\FSViewer.exe\" \"%%1\"" /f
  10. goto :EOF
  11. :2
  12. reg delete "HKLM\SOFTWARE\Classes\%~1\shell\open1" /f
  13. goto :EOF
复制代码

TOP

回复 3# kli2018
改成这样
  1. findstr /b "%ext%"
复制代码
更加准确就
  1. findstr /b "%ext: == %"
复制代码

TOP

回复 4# smss

谢谢

TOP

回复 5# went

谢谢

TOP

返回列表