找回密码
 加入
搜索
查看: 4386|回复: 14

[AU3基础] [已解决]枚举注册表指定项显示对应值的问题?

  [复制链接]
发表于 2010-7-19 16:22:07 | 显示全部楼层 |阅读模式
本帖最后由 newuser 于 2010-7-19 18:34 编辑

枚举执行注册表项,要求注册表的具体值项与值一一对应,问题如下:
1.$listval = StringSplit(StringTrimRight ($list,1),"|")中为什么要StringTrimRight呢?要删除什么符号呢?
2.MsgBox(0,$listerery[1],$listerery[2])也不是我要得结果?
#NoTrayIcon
Local $list = ''
$run1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
$run2 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce"
$run3 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$run4 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
$run5 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx"
$run6 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices"
$run7 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesEX"
$Runval = StringSplit($run1 & "|" & $run2 & "|" & $run3 & "|" & $run4 & "|" & $run5 & "|" & $run6 & "|" & $run7, "|")
;将以上7个可能存在启动项的注册表键连接起来
For $Run In $Runval;对以上7个连接的每一个启动键进行For循环
        For $var = 1 To 1000

                $Runkey = RegEnumVal($Run, $var);枚举每一个启动项下的值项

                If @error <> 0 Then ExitLoop(1)

                                $list &= $Run & " " & $Runkey & "|";该语句很重要
        Next
Next
$listval = StringSplit(StringTrimRight ($list,1),"|");这里为什么要StringTrimRight($list,1)呢?
;For $i=1 To $listval[0]
;        MsgBox(0,"第"&$i&"个"&"开机启动项是",$listval[$i])
;        RegDelete(0,'',
;Next
For $var In $listval
        $listerery=StringSplit($var," ",1);这里完成了值项与值的分离
        MsgBox(0,$listerery[1],$listerery[2])
Next

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-7-19 17:30:36 | 显示全部楼层
因为有这句$list &= $Run & " " & $Runkey & "|"
最后一个字符是"|",所以要删除
发表于 2010-7-19 17:41:02 | 显示全部楼层
第22行最后加个标志2
第28行用空格做分割不妥
发表于 2010-7-19 17:45:30 | 显示全部楼层
28、29两行在这里建议使用
        $listerery=StringRegExp($var, '(.+?) (.+)', 3);这里完成了值项与值的分离
        MsgBox(0,$listerery[0],$listerery[1])
以避免$var里面有多个空格时出错
 楼主| 发表于 2010-7-19 18:10:28 | 显示全部楼层
回复 2# 3mile
$listval = StringSplit(StringTrimRight ($list,1),"|");这里为什么要StringTrimRight($list,1)呢?
但是在这里不是已经分离了吗?那"|"不就是已经没有了吗?如果StringTrimRight ($list,1)真是删除了"|",那么最外层StringSplit()又是通过什么分割符号分离字符串的呢?还是糊涂?
 楼主| 发表于 2010-7-19 18:15:18 | 显示全部楼层
回复 4# afan
谢谢,参照老大提示已经解决,但将$list &= $Run & "&" & $Runkey & "|"此处的空格替换成"&"后,用 正则表达式就不好用了,适合$listerery=StringRegExp($var, '(.+?) (.+)', 3)有关吧,因为之前是用空格的.
老大有空能做个正则表达式的视频讲座吗?确实读了几篇文章,但最后都放弃了!
#NoTrayIcon
Local $list = ''
$run1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
$run2 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce"
$run3 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$run4 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce"
$run5 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx"
$run6 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices"
$run7 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesEX"
$Runval = StringSplit($run1 & "|" & $run2 & "|" & $run3 & "|" & $run4 & "|" & $run5 & "|" & $run6 & "|" & $run7, "|")
;将以上7个可能存在启动项的注册表键连接起来
For $Run In $Runval;对以上7个连接的每一个启动键进行For循环
        For $var = 1 To 1000
                $Runkey = RegEnumVal($Run, $var);枚举每一个启动项下的值项
                If @error <> 0 Then ExitLoop(1)
                                $list &= $Run & " " & $Runkey & "|";该语句很重要
        Next
Next
$listval = StringSplit(StringTrimRight ($list,1),"|",2);这里为什么要StringTrimRight($list,1)呢?
;若标志为2,关闭第一个元素中的返回数量 - 方便使用 UBound() 得到此基于0开始的数组.
;For $i=1 To $listval[0]
;        MsgBox(0,"第"&$i&"个"&"开机启动项是",$listval[$i])
;        RegDelete(0,'',
;Next
For $var In $listval
        ;$listerery=StringSplit($var," ",1);这里完成了值项与值的分离
        ;MsgBox(0,$listerery[1],$listerery[2])
                $listerery=StringRegExp($var, '(.+?) (.+)', 3);这里完成了值项与值的分离
        MsgBox(0,$listerery[0],$listerery[1])
Next
发表于 2010-7-19 18:18:30 | 显示全部楼层
替换成“&”之后就要用 $listerery=StringRegExp($var, '(.+?)&(.+)', 3)
发表于 2010-7-19 18:22:25 | 显示全部楼层
视频讲座… 我会晕倒~ “写”个入门级的教程都会把人搞晕~
发表于 2010-7-19 18:28:11 | 显示全部楼层
回复 5# newuser
看如下代码,如果不删除最后的“|”则数组变大。
Local $str
For $i=0 To 100
        $str&=$i&"|"
Next
$val_1 = StringSplit($str,"|")
$val_2=StringSplit(StringTrimRight($str,1),"|")
MsgBox(0,0,UBound($val_1)&@CRLF&UBound($val_2));注意这行

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-7-19 18:29:39 | 显示全部楼层
本帖最后由 newuser 于 2010-7-19 18:31 编辑

回复 7# afan
此处:$list &= $Run & "&" & $Runkey & "|"
此处:$listval = StringSplit(StringTrimRight ($list,1),"|",2),那么字符串是按照"|"分割的,那么StringTrimRight ($list,1)又是要截除什么?是"|"?不应该,因为stringsplit()要用它啊!是截除空格吗?那如果没有空格不就删除注册表值项对应的具体值吗 ?我计算机的相关枚举项也没有看到空格啊!可要不用他,显示就用个空显示,就是窗口有标题没内容的那种?怎么回事呢?
不好意思,我又忘记StringSplit(StringTrimRight ($list,1),"|",2)中的2了,不用StringTrimRight 也好使了!
发表于 2010-7-19 18:32:37 | 显示全部楼层
$list &= $Run & "&" & $Runkey & "|"

StringTrimRight ($list,1) 是删除右边1位。 $list 的右边一位一定会是 |,所以就是删除了末尾的 | 而已
发表于 2010-7-20 01:43:51 | 显示全部楼层
启动项?给你一段参考
Func makeitem($num)
        If $num = 2 Then
                _read("HKCU\SOFTWARE\Policies\Microsoft\Windows\SYSTEM\Scripts")
                _read("HKCU\SOFTWARE\Policies\Microsoft\Windows\SYSTEM\Scripts\Logon")
                _read("HKCU\SOFTWARE\Microsoft\Windows\SYSTEM\Scripts")
                _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServices")
                _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\SYSTEM\Shell")
                _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunServicesOnce")
                _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\SYSTEM\Shell")
                _read("HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell")
                _read("HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\Load")
                _read("HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\Run")
                _read("HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Install\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce")
                _read("HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Install\SOFTWARE\Microsoft\Windows\CurrentVersion\RunonceEx")
                _read("HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Install\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
                _read("HKCU\SOFTWARE\Microsoft\Active Setup\Installed Components")
                _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\ShellServiceObjectDelayLoad")
                _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved")
                _read("HKCU\SOFTWARE\Microsoft\Internet Explorer\Desktop\Components")
                _read("HKCU\SOFTWARE\Microsoft\Internet Explorer\UrlSearchHooks")
                _read("HKCU\SOFTWARE\Microsoft\Internet Explorer\Explorer Bars")
                _read("HKCU\SOFTWARE\Microsoft\Internet Explorer\Extensions")
                _read("HKCU\SOFTWARE\Microsoft\Command Processor\Autorun")
                _read("HKCU\Control Panel\Desktop\Scrnsave.exe")
                _read($CCS & "Control\Terminal Server\Wds\rdpwd\StartupPrograms")
                _read($CCS & "Services")
                _read($CCS & "Control\Session Manager\BootExecute")
                _read($CCS & "Control\Session Manager\KnownDlls")
                _read($CCS & "Control\BootVerificationProgram\ImageName")
                _read($CCS & "Control\Print\Monitors")
                _read($CCS & "Control\Lsa\Authentication Packages")
                _read($CCS & "Control\Lsa\Notification Packages")
                _read($CCS & "Control\Lsa\Security Packages")
                _read($CCS & "Services\WinSock2\Parameters\Protocol_Catalog9")
                _read($CV & "RunServices")
                _read($CV & "RunServicesOnce")
                _read($CV & "ShellServiceObjectDelayLoad")
                _read($CV & "Policies\SYSTEM\Shell")
                _read($CV & "Policies\Explorer\Run")
                _read($CV & "Explorer\ShellExecuteHooks")
                _read($CV & "Shell Extensions\Approved")
                _read($CV & "Explorer\SharedTaskScheduler")
                _read($CV & "ShellServiceObjectDelayLoad")
                _read($CV & "Explorer\Browser Helper Objects")
                _read("HKLM\SOFTWARE\Classes\Protocols\Filter")
                _read("HKLM\SOFTWARE\Classes\Protocols\Handler")
                _read("HKLM\SOFTWARE\Classes\Folder\Shellex\ColumnHandlers")
                _read("HKLM\SOFTWARE\Classes\Exefile\Shell\Open\Command\(Default)")
                _read("HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components")
                _read("HKLM\SOFTWARE\Microsoft\Command Processor\Autorun")
                _read("HKLM\SOFTWARE\Microsoft\Internet Explorer\Toolbar")
                _read("HKLM\SOFTWARE\Microsoft\Internet Explorer\Explorer Bars")
                _read("HKLM\SOFTWARE\Microsoft\Internet Explorer\Extensions")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AppSetup")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Taskman")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Install\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Install\SOFTWARE\Microsoft\Windows\CurrentVersion\RunonceEx")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\TerminalServer\Install\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\Appinit_Dlls")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SYSTEM")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\UIHost")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Notify")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GinaDLL")
                _read("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Taskman")
                _read("HKLM\SOFTWARE\Policies\Microsoft\Windows\SYSTEM\Scripts")
                _read("HKLM\SOFTWARE\Policies\Microsoft\Windows\SYSTEM\Scripts\Logon")
        EndIf
        _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx")
        _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce")
        _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run")
        _read("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")
        _read($CV & "RunOnceEx")
        _read($CV & "RunOnce")
        _read($CV & "Policies\Explorer\Run")
        _read($CV & "Run")
        addlnk(@StartupCommonDir)
        addlnk(@StartupDir)
EndFunc   ;==>makeitem
Func addlnk($j)
        Select
                Case FileExists($j) = 1
                        $filelist = _FileListToArray($j)
                        If @error = 0 Then
                                $w = _GUICtrlListView_GetItemCount($hTree6)
                                For $i = 1 To $filelist[0]
                                        _GUICtrlListView_AddItem($hTree6, $filelist[$i], $w + $i)
                                        _GUICtrlListView_AddItem($hTree6, $w + $i, $j, 2)
                                Next
                        EndIf
        EndSelect
EndFunc   ;==>addlnk
Func delstart()
        $Count = _GUICtrlListView_GetItemCount($hTree6)
        For $i = 0 To $Count
                If _GUICtrlListView_GetItemChecked($hTree6, $i) Then
                        RegDelete(_GUICtrlListView_GetItemText($hTree6, $i, 2), _GUICtrlListView_GetItemText($hTree6, $i, 0))
                        _GUICtrlListView_SetItemSelected($hTree6, $i)
                        _GUICtrlListView_DeleteItemsSelected($hTree6)
                EndIf
        Next
EndFunc   ;==>delstart
Func _read($k)
        $j = 1
        While 1
                $key = RegEnumVal($k, $j)
                $var = RegRead($k, $key)
                If @error <> 0 Then ExitLoop
                _GUICtrlListView_AddItem($hTree6, $key, $u)
                _GUICtrlListView_AddSubItem($hTree6, $u, $var, 1)
                _GUICtrlListView_AddSubItem($hTree6, $u, $k, 2)
                $u += 1
                $j += 1
        WEnd
EndFunc   ;==>_read
Func backup()
        Local $regfile = @MyDocumentsDir & "\startup.reg"
        If FileExists($regfile) = 0 Then
                FileWrite($regfile, "Windows Registry Editor Version 5.00" & @CRLF)
        EndIf
        For $i = 0 To _GUICtrlListView_GetItemCount($hTree6)
                Select
                        Case StringInStr(_GUICtrlListView_GetItemText($hTree6, $i, 2), "HKLM") <> 0
                                FileWrite($regfile, "[HKEY_LOCAL_MACHINE" & StringTrimLeft(_GUICtrlListView_GetItemText($hTree6, $i, 2), 4) & "]" & @CRLF)
                        Case StringInStr(_GUICtrlListView_GetItemText($hTree6, $i, 2), "HKCU") <> 0
                                FileWrite($regfile, "[HKEY_CURRENT_USER" & StringTrimLeft(_GUICtrlListView_GetItemText($hTree6, $i, 2), 4) & "]" & @CRLF)
                EndSelect
                FileWrite($regfile, '"' & _GUICtrlListView_GetItemText($hTree6, $i, 0) & '"="' & _GUICtrlListView_GetItemText($hTree6, $i, 1) & '"' & @CRLF)
        Next
        MsgBox('', 'OK', "备份完成!")
EndFunc   ;==>backup
发表于 2010-7-20 01:45:07 | 显示全部楼层
别照抄,里面的好多变量我是在脚本开始定义的,这里没有,只当作参考而已
 楼主| 发表于 2010-7-20 07:51:59 | 显示全部楼层
回复 13# netegg
谢谢老大,我会好好学习的!
 楼主| 发表于 2010-7-20 07:54:13 | 显示全部楼层
回复 9# 3mile
谢谢,明白了,我总是再头脑中固执的认为是:
0|1|....|9|10
但其实是

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-3 14:24 , Processed in 0.158836 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表