Board logo

标题: [求助]如何用reg 来查找注表某个值,并取出某个值?? [打印本页]

作者: workmanlr     时间: 2009-4-19 13:27    标题: [求助]如何用reg 来查找注表某个值,并取出某个值??

如题:
我想用reg 来查这个值:
Distinguished-Name

并出Distinguished-Name  数据中的一部分:
CN=张三,OU=ddd,OU=kkk,OU=uuuDC=Freedom,DC=org

我想要取出  张三 这个值,并付于某个变量:  set name=张三

关键是怎么取出张三这个值来??
作者: jj65535     时间: 2009-4-19 13:54
你这种没环境!没准确参数!
高手们很难给你答案的!
我这个新人发个例子!自己想................

注册表环境!(操作系统WIN2003)
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER]
"Distinguished-Name"="CN=张三,OU=ddd,OU=kkk,OU=uuuDC=Freedom,DC=org"

运行环境:WIN2003 CMD
for /f "tokens=1 delims=," %%l in ('reg QUERY "HKEY_CURRENT_USER" /v "Distinguished-Name"^|find /i "CN="') do (
        for /f "tokens=2 delims==" %%m in ("%%l") do set name=%%m )
echo %name%
作者: workmanlr     时间: 2009-4-19 14:39
谢谢,操作系统是xp
作者: workmanlr     时间: 2009-4-19 14:44
我把你写的代码加存为aaa.bat
执行结果如下:
C:\>aaa

C:\>for /F "tokens=1 delims=," %l in ('reg QUERY "HKEY_CURRENT_USER" /v "Disting
uished-Name"|find /i "CN="') do (for /F "tokens=2 delims==" %m in ("%l") do set
name=%m  )

错误: 系统找不到指定的注册表项或值

C:\>echo
ECHO 处于打开状态。
作者: workmanlr     时间: 2009-4-19 14:54
你这个是要找到具体的键值,
因为这个键值是在S-1-5-21-3066645261-2536786027-3422793319-1117下面的,因为每台电脑的sid都不一样。所以不能用你这个方法来找。

还是谢谢你
作者: workmanlr     时间: 2009-4-19 23:07
各位大侠帮帮忙
作者: jj65535     时间: 2009-4-20 03:13
你当然不能照抄啊!我的只是例子
注册表环境!(操作系统WIN2003)
我注明是这注册表例子为例子!
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER]
"Distinguished-Name"="CN=张三,OU=ddd,OU=kkk,OU=uuuDC=Freedom,DC=org"

你自己不能完成就要提供完整的调试环境!
注册表的完整目标位置!要没每台机器都不同就要提供多个成为比较例子的注册表例子

你这种不是固定注册表项现象
按我的水平只能用regedit 来导出大项来用其他命令来查找判断!
看其他高手的意见吧
作者: workmanlr     时间: 2009-4-20 05:55
恩,现在就是不是固定注册表项,有什么方法吗??
作者: workmanlr     时间: 2009-4-20 11:30
有办法实现吗??
作者: newxso     时间: 2009-4-20 18:51
在Win2K工具包中有一个用来搜索注册表的工具,从整个注册表中搜索某字符串,只需几十秒时间:

dureg [/cr | /cu | /u | /lm | /a] [/s | /d] ["registry path"] ["string to search"]

    /cr                 Find the size of HKEY_CLASSES_ROOT
    /cu                 Find the size of HKEY_CURRENT_USER
    /u                  Find the size of HKEY_USERS
    /lm                 Find the size of HKEY_LOCAL_MACHINE
    /a                  All. Find the size of entire registry.

    </Subtree switch>   "registry path"  Find the size of any registry key
    e.g. dureg /lm "software\microsoft"  finds the size of the HKLM\Software\Microsoft key

    /s "string"         Search for string in the registry
    e.g. dureg /s "video" finds all occurrences of "video" in the registry

    /s  [/subtree switch] "string"   Search for string in the registry subtree
    e.g. dureg /lm /s "video" finds all occurrences of "video" in the HKLM
    (to stop a search, press Ctrl+Break)

http://support.microsoft.com/kb/317382


例如:dureg /s "Distinguished-Name" 可以从注册表中搜索包含 Distinguished-Name 字符串的项目,可以用定向符把结果保存到临时文件,或嵌套到 for 语句中处理结果。

[ Last edited by newxso on 2009-4-20 at 20:00 ]
附件 1: dureg.rar (2009-4-20 18:51, 14.74 K,下载次数: 8)