Board logo

标题: [注册表类] [已解决]求教:如何用批处理把%AllUsersProfile%里面的某个文件加入注册表? [打印本页]

作者: solan    时间: 2015-4-12 22:14     标题: [已解决]求教:如何用批处理把%AllUsersProfile%里面的某个文件加入注册表?

本帖最后由 solan 于 2015-4-14 09:47 编辑

如题,要求加入注册表后是绝对路径,不是相对路径,因为我是想让它跟随系统的,而系统有可能安装在c盘D盘或其它盘,我现在想到两种方法,但都不能如愿,我先说说我的方法,然后求各位好心人帮我看看,我该怎么做?
  方法一:写批处理代码:
  1. @echo off
  2. echo Windows Registry Editor Version 5.00 >%AllUsersProfile%\nx_flex\router.reg
  3. echo [HKEY_CLASSES_ROOT\UGpartfile\shell\open\command] >>%AllUsersProfile%\nx_flex\router.reg
  4. cd /d %AllUsersProfile%
  5. echo @="\"%AllUsersProfile%\\nx_flex\\ugs_router.exe\" -ug -use_file_dir \"%%1\"" >>%AllUsersProfile%\nx_flex\router.reg
  6. reg import "%AllUsersProfile%\nx_flex\router.reg"
  7. pause
复制代码
执行该批处理后所得注册表文件内容为
  1. Windows Registry Editor Version 5.00
  2. [HKEY_CLASSES_ROOT\UGpartfile\shell\open\command]
  3. @="\"C:\ProgramData\\nx_flex\\ugs_router.exe\" -ug -use_file_dir \"%1\""
复制代码
在C:\ProgramData里面少了个\所以不能注册,我不知道怎么让批处理自动加上这个\

    方法二:写批处理代码:
  1. @echo off
  2. reg add "HKEY_CLASSES_ROOT\UGpartfile\shell\open\command" /f /v "" /t "REG_SZ" /d "%AllUsersProfile%\nx_flex\ugs_router.exe\" -ug -use_file_dir \"%%1\"
  3. pause
复制代码
这回执行该批处理后,能加入注册表了,但是注册表的数值数据里面少了个引号"      如下:
C:\ProgramData\nx_flex\ugs_router.exe" -ug -use_file_dir "%1"         就是C:盘符后面少了个",所以ugs_router.exe不能执行,也就是UG文件不能双击打开,如果是这样就好了
"C:\ProgramData\nx_flex\ugs_router.exe" -ug -use_file_dir "%1"  

      请好心人帮忙啊,我好着急哦。
作者: gawk    时间: 2015-4-13 08:27

  1. @echo off
  2. reg add "HKEY_CLASSES_ROOT\UGpartfile\shell\open\command" /f /v "" /t "REG_SZ" /d """"%AllUsersProfile%\nx_flex\ugs_router.exe\""" -ug -use_file_dir """%%1""""
  3. pause
复制代码

作者: pcl_test    时间: 2015-4-13 14:24

用\转义双引号
  1. @echo off
  2. reg add "HKEY_CLASSES_ROOT\UGpartfile\shell\open\command" /f /t "REG_SZ" /d "\"%AllUsersProfile%\nx_flex\ugs_router.exe\" -ug -use_file_dir \"%%1\""
  3. pause
复制代码

作者: pcl_test    时间: 2015-4-13 14:26

问题得到解决后请在标题最前面注明[已解决]
http://www.bathome.net/thread-3473-1-1.html
作者: solan    时间: 2015-4-13 21:25

回复 2# gawk

谢谢,但是错误提示:无效的语法reg add
作者: solan    时间: 2015-4-13 21:31

回复 3# pcl_test
老大,你好厉害啊,非常好用,谢谢谢谢!!那么我的第一个方法错在哪儿呢?如果老大方便的话,能不能也改改呢,
作者: pcl_test    时间: 2015-4-13 21:48

回复 6# solan
  1. @echo off
  2. set "str=%AllUsersProfile%"
  3. (echo Windows Registry Editor Version 5.00
  4. echo [HKEY_CLASSES_ROOT\UGpartfile\shell\open\command]
  5. echo @="\"%str:\=\\%\\nx_flex\\ugs_router.exe\" -ug -use_file_dir \"%%1\"")>"%AllUsersProfile%\nx_flex\router.reg"
  6. regedit /s "%AllUsersProfile%\nx_flex\router.reg"
  7. pause
复制代码

作者: solan    时间: 2015-4-13 22:24

回复 7# pcl_test


    这个也测试了,非常对,姜还是老的辣啊,真的谢谢你了,以后再来请教
作者: gawk    时间: 2015-4-14 12:29

回复 5# solan


    XP还是Win7?
作者: solan    时间: 2015-4-14 15:14

现在是win7,xp上还没测试,如果不行,那问题没了
作者: solan    时间: 2015-4-14 15:39

果然,xp上不能用,请pcl_test老大抽空改改,这两个方法xp和win7上都要能用,谢谢
作者: gawk    时间: 2015-4-14 16:08

回复 11# solan


    2楼代码在XP上报什么错
作者: solan    时间: 2015-4-14 16:26

2楼代码在xp上报错:命令行参数太多
作者: solan    时间: 2015-4-14 16:36

再经测试,7楼的代码是对的,xp上能用,因为我刚才在xp上是临时测试,当时没有这个nx_flex文件夹
作者: solan    时间: 2015-4-14 16:41

3楼代码在xp上不能用,pcl_test老大能不能改改,如果实在没空也没关系啦,我就用你7楼的代码,谢谢,祝你生活愉快
作者: apang    时间: 2015-4-14 16:43

默认值的话,印象中好像加 /ve 参数
作者: apang    时间: 2015-4-14 16:48

  1. reg add "HKEY_CLASSES_ROOT\UGpartfile\shell\open\command" /f /ve /t "REG_SZ" /d "\"%AllUsersProfile%\nx_flex\ugs_router.exe\" -ug -use_file_dir \"%%1\""
复制代码
自己试下
作者: solan    时间: 2015-4-14 18:17

回复 17# apang


    在xp顺利通过,谢谢
至此,所有问题解决了,各位朋友,在此谢过啦。批处理之家,不错的地方。




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2