批处理修改注册表键值

roebin 2010-05-21 05:18:07
请问我想用一个批处理实现。

对于
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"ProxyEnable"=

如果"ProxyEnable"=dword:00000000则设置为"ProxyEnable"=dword:00000001,
如果"ProxyEnable"=dword:00000001则设置为"ProxyEnable"=dword:00000000

这样的批处理要如何写呢,非常感谢。
...全文
776 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
roebin 2010-05-26
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 ljc007 的回复:]

批处理的if...else语法是这样的(注意括号的位置):
if xxx (
...
) else if xxx (
...
)
[/Quote]

多谢,搞定。
ljc007 2010-05-25
  • 打赏
  • 举报
回复
批处理的if...else语法是这样的(注意括号的位置):
if xxx (
...
) else if xxx (
...
)
roebin 2010-05-25
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 just4 的回复:]

此时不应有 j"=="0x1",,,以上我写的是命令,不是批处理啥,

对于for,直接cmd中写命令变量是单%i,如放在批处理中就是%%i
[/Quote]

非常感谢,现在有些明白了,但是还有个问题。对于“for /f "skip=2 tokens=2,3*" %i in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable') do if "%j"=="0x1" reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 0 /f”是实现了当ProxyEnable为1时更改为0,如果当前值为0要如何更改为1呢,如果继续在后面加上else "%i"=="0x0" reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 1 /f 这样写这个命令并没有执行。
就是just4 2010-05-24
  • 打赏
  • 举报
回复
此时不应有 j"=="0x1",,,以上我写的是命令,不是批处理啥,

对于for,直接cmd中写命令变量是单%i,如放在批处理中就是%%i
就是just4 2010-05-24
  • 打赏
  • 举报
回复
楼主要仔细看看啥,最后一句才是需要的啥,for /f "skip=2 tokens=2,3*" %i in
roebin 2010-05-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 just4 的回复:]

BatchFile code
reg /?
reg add /?
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 0
reg add "HKEY_CURRENT_USER\Software\Microso……
[/Quote]

感谢您的回复,但是执行的时候应该和我的预想不同,应该是先判断,再更改键值。
您的语句是直接将键值改为0,然后更改为1,我的想法是,判断目前系统中键值,如果为0,更改为1,如果当前系统为1,则更改为0。

另外执行“for /f "skip=2 tokens=2,3*" %i in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable') do if "%j"=="0x1" reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 0 /f”

报错“此时不应有 j"=="0x1" reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre
ntVersion\Internet。”

LovePurple 2010-05-22
  • 打赏
  • 举报
回复
学习~~~~~~~~~~~
tangyunyun 2010-05-22
  • 打赏
  • 举报
回复
楼主,用来做什么?
ljc007 2010-05-21
  • 打赏
  • 举报
回复
结帖率:33.33%
就是just4 2010-05-21
  • 打赏
  • 举报
回复
[code=BatchFile]reg /?
reg add /?
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 0
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 1

for /f "skip=2 tokens=2,3*" %i in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable') do if "%j"=="0x1" reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t reg_dword /d 0 /f
[/code]

18,138

社区成员

发帖
与我相关
我的任务
社区描述
Windows客户端使用相关问题交流社区
社区管理员
  • Windows客户端使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧