批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程
[批处理文件精品]批处理版照片整理器[批处理文件精品]纯批处理备份&还原驱动在线第三方下载
返回列表 发帖

[注册表类] 批处理检测文件是否存在 并运行命令(望高手解答)

  1. @echo off
  2. if exist C:\1.txt (
  3. taskkill /f /im iexplo*
  4. ECHO ---正在解除权限.........
  5. set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
  6. :fix
  7. del %tmp%\ko.txt/q
  8. echo "%route%"[7]>>%tmp%\ko.txt
  9. regini %tmp%\ko.txt
  10. ping 127.1 -n 3
  11. set route=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
  12. :fix
  13. del %tmp%\ko.txt/q
  14. echo "%route%"[7]>>%tmp%\ko.txt
  15. regini %tmp%\ko.txt
  16. ping 127.1 -n 3
  17. ECHO ---删除信任
  18. Reg.exe delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges" /f
  19. ping 127.1 -n 2
  20. ECHO 开始配置智联T9运行环境……
  21. REM ECHO 该设置不会对您的电脑使用带来影响
  22. REM ---增加信任站点
  23. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /f > nul
  24. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /v ":Range" /t REG_SZ          /d "*.9csoft.com" /f > nul
  25. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /v "http"     /t REG_DWORD /d 2                        /f > nul
  26. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /f > nul
  27. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /v ":Range" /t REG_SZ          /d "*.zlt9.com" /f > nul
  28. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /v "http"     /t REG_DWORD /d 2                        /f > nul
  29. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /f > nul
  30. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /v ":Range" /t REG_SZ          /d "*.zlt9.cn" /f > nul
  31. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /v "http"     /t REG_DWORD /d 2                        /f > nul
  32. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /f > nul
  33. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /v ":Range" /t REG_SZ          /d "61.128.196.*" /f > nul
  34. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /v "http"     /t REG_DWORD /d 2                        /f > nul
  35.       
  36. REM ---设置IE信任区域
  37. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "DisplayName" /t REG_SZ          /d "可信站点"   /f > nul
  38. ECHO ---正在设置权限.........
  39. set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
  40. :fix
  41. del %tmp%\ko.txt/q
  42. echo "%route%"[8]>>%tmp%\ko.txt
  43. regini %tmp%\ko.txt
  44. ping 127.1 -n 3
  45. set route=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
  46. :fix
  47. del %tmp%\ko.txt/q
  48. echo "%route%"[8]>>%tmp%\ko.txt
  49. regini %tmp%\ko.txt
  50. ) else (echo >nul 2>nul)
  51. ping 127.1 -n 2
  52. set dir=C:\WINDOWS\Temp
  53. rd /s /q "%dir%"
  54. exit
  55. ) else (
  56.     goto :i
  57. )
  58. goto :eof
  59. :i
  60. echo 不存在文件
复制代码
上面是在论坛搜索 自己的做的  主要目的是实现 平 判断文件是否存在并运行命令  实现注册表设置访问权限 在设置注册表相干设置      如果不存在文件  就自动退出       现在能做出判断  并且运行命令  可是开头 if exist C:\1.txt 这个命令运行后  批处理设置注册表不能实现   如果去掉if exist C:\1.txt 这个命令后 就能设置注册表权限    麻烦论坛里高手帮忙看看 谢谢

目测 少个IF 重复那么多标签干嘛呢

TOP

回复 1# 5209520


    这个代码里有3个左括号、4个右括号。你检查一下看看是哪里多了一个右括号
【批处理在线视频分享】http://bbs.bathome.net/thread-31727-1-1.html
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html

我帮忙写的代码不需要付钱,不用找我要支付宝或微信账号。如果一定要给,请到微信群给大家发红吧。

TOP

本帖最后由 5209520 于 2019-11-29 12:01 编辑

@echo off
if exist C:\1.txt (
taskkill /f /im iexplo*
ECHO ---正在解除权限.........
set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
:fix
del %tmp%\ko.txt/q
echo "%route%"[7]>>%tmp%\ko.txt
regini %tmp%\ko.txt
ping 127.1 -n 3
set route=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
:fix
del %tmp%\ko.txt/q
echo "%route%"[7]>>%tmp%\ko.txt
regini %tmp%\ko.txt
ping 127.1 -n 3
ECHO ---删除信任
Reg.exe delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges" /f
ping 127.1 -n 2
ECHO 开始配置智联T9运行环境……
REM ECHO 该设置不会对您的电脑使用带来影响
REM ---增加信任站点
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /v ":Range" /t REG_SZ          /d "*.9csoft.com" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /v "http"     /t REG_DWORD /d 2                        /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /v ":Range" /t REG_SZ          /d "*.zlt9.com" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /v "http"     /t REG_DWORD /d 2                        /f > nul

REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /v ":Range" /t REG_SZ          /d "*.zlt9.cn" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /v "http"     /t REG_DWORD /d 2                        /f > nul

REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /v ":Range" /t REG_SZ          /d "61.128.196.*" /f > nul
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /v "http"     /t REG_DWORD /d 2                        /f > nul
      
REM ---设置IE信任区域
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "DisplayName" /t REG_SZ          /d "可信站点"   /f > nul
ECHO ---正在设置权限.........
set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
:fix
del %tmp%\ko.txt/q
echo "%route%"[8]>>%tmp%\ko.txt
regini %tmp%\ko.txt
ping 127.1 -n 3
set route=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
:fix
del %tmp%\ko.txt/q
echo "%route%"[8]>>%tmp%\ko.txt
regini %tmp%\ko.txt
) else (echo >nul 2>nul)
ping 127.1 -n 2
set dir=C:\WINDOWS\Temp
rd /s /q "%dir%"
exit
我重新编辑了 没有要最好那部分  但是    批处理设置权限  这个段代码 使用不能生效   (set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
:fix
del %tmp%\ko.txt/q
echo "%route%"[7]>>%tmp%\ko.txt
regini %tmp%\ko.txt  )           但是去掉  if exist C:\1.txt (   这个段代码 就能生效  是什么原因?、

TOP

本帖最后由 terse 于 2019-11-29 14:31 编辑

去掉一楼的52行试一下呢
另外 括号里变量 %route% 加个延迟用!route!

TOP

本帖最后由 5209520 于 2019-11-29 14:59 编辑

%route% 改老也不 提示设置失败     能否帮忙编辑一下 谢谢

TOP

  1. @echo off
  2. if exist C:\1.txt (
  3.   goto label1
  4.   ) else goto end
  5. :label1
  6. taskkill /f /im iexplo*
  7. ECHO ---正在解除权限.........
  8. set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
  9. :fix
  10. del %tmp%\ko.txt/q
  11. echo "%route%"[7]>>%tmp%\ko.txt
  12. regini %tmp%\ko.txt
  13. ping 127.1 -n 3
  14. set route=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
  15. :fix
  16. del %tmp%\ko.txt/q
  17. echo "%route%"[7]>>%tmp%\ko.txt
  18. regini %tmp%\ko.txt
  19. ping 127.1 -n 3
  20. ECHO ---删除信任
  21. Reg.exe delete "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges" /f
  22. ping 127.1 -n 2
  23. ECHO 开始配置智联T9运行环境……
  24. REM ECHO 该设置不会对您的电脑使用带来影响
  25. REM ---增加信任站点
  26. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /f > nul
  27. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /v ":Range" /t REG_SZ          /d "*.9csoft.com" /f > nul
  28. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range302" /v "http"     /t REG_DWORD /d 2                        /f > nul
  29. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /f > nul
  30. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /v ":Range" /t REG_SZ          /d "*.zlt9.com" /f > nul
  31. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range303" /v "http"     /t REG_DWORD /d 2                        /f > nul
  32. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /f > nul
  33. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /v ":Range" /t REG_SZ          /d "*.zlt9.cn" /f > nul
  34. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range304" /v "http"     /t REG_DWORD /d 2                        /f > nul
  35. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /f > nul
  36. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /v ":Range" /t REG_SZ          /d "61.128.196.*" /f > nul
  37. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range301" /v "http"     /t REG_DWORD /d 2                        /f > nul
  38.       
  39. REM ---设置IE信任区域
  40. REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2" /v "DisplayName" /t REG_SZ          /d "可信站点"   /f > nul
  41. ECHO ---正在设置权限.........
  42. set route=HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData
  43. :fix
  44. del %tmp%\ko.txt/q
  45. echo "%route%"[8]>>%tmp%\ko.txt
  46. regini %tmp%\ko.txt
  47. ping 127.1 -n 3
  48. set route=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\2
  49. :fix
  50. del %tmp%\ko.txt/q
  51. echo "%route%"[8]>>%tmp%\ko.txt
  52. regini %tmp%\ko.txt
  53. exit /b
  54. :end
  55. echo 不存在文件
复制代码
Email:guangchengwang@163.com
QQ:49908356

TOP

回复 7# flashercs


  谢谢解答 666 谢谢

TOP

返回列表