找回密码
 加入
搜索
查看: 10835|回复: 22

[系统综合] [已解决]请帮助找出以下代码的错误?

  [复制链接]
发表于 2010-9-25 15:42:37 | 显示全部楼层 |阅读模式
本帖最后由 newuser 于 2010-9-26 12:01 编辑

执行假死机?
Dim  $i,$CommonReg
$CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates"
_EnumRegProcess1()
_EnumRegProcess2()
Func _EnumRegProcess1()
    While  1
            $i +=1
            $EnumResult=RegEnumKey($CommonReg,$i)
            If @error <> 0  Then  ExitLoop
            IniWrite(@ScriptDir&"\FixedPatchsList1.ini","已安装补丁列表",$EnumResult,"1")
    WEnd
EndFunc
Func _EnumRegProcess2()
        While 1
            $Array=IniReadSection(@ScriptDir&"\FixedPatchsList1.ini","已安装补丁列表")
            If @error Then
                    MsgBox(0,"错误提示:","发生读取初始化文件错误")
                    ExitLoop
            Else
                    For $i=1 To $Array[0][0]
                                String($Array[$i][0])
                            If StringInStr($Array[$i][0],"KB") Then
                                    IniWrite(@ScriptDir&"\FixedPatchsList2.ini","已安装补丁列表",$Array[$i][0],"1")
                            Else
                                    $CommonReg=$Array[$i][0]
                                        $EnumResult=RegEnumKey($CommonReg,$i)
                                        If @error <> 0  Then  ExitLoop
                                        $KBString = StringRegExpReplace($EnumResult, '.*?(KB\d+)[^\d]*?.*', '$1')
                                        If @extended > 0 Then IniWrite(@ScriptDir&"\FixedPatchsList2.ini","已安装补丁列表",$KBString,"1")
                                EndIf
                        Next
                EndIf
        WEnd
EndFunc

评分

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

查看全部评分

发表于 2010-9-25 15:52:26 | 显示全部楼层
RegEnumKey不会报错,如果要退出循环 if $EnumResult='' then
 楼主| 发表于 2010-9-25 16:11:34 | 显示全部楼层
回复 2# netegg
我是想执行完循环得到那个最终的INI文件再退出,那个if 判断该加到哪里呢?
其实我就是想执行向下面代码的类似结果,但显然它的判断的分支少了,而且看上去代码不精简!!!
#cs
新增对分支HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates的枚举,以下都是该分支下的分支(注意有 XP和WinServer2003):
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP0
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP2
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP3
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP4
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP10
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP2
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP3
#ce
#include <File.au3>
Dim  $i,$Array
Dim  $EnumRegPath1,$EnumRegPath2,$EnumRegPath3
Dim  $XP_SP0,$XP_SP2,$XP_SP3,$XP_SP4,$2003_SP10,$2003_SP2,$2003_SP3
Dim  $CommonReg
;$EnumRegPath1="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix"
;$EnumRegPath2="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
$CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates"
_EnumRegProcess1()
If @OSVersion="WIN_XP" Then
        _EnumRegProcess2()
        _EnumRegProcess3()
        _EnumRegProcess4()
        _EnumRegProcess5()
ElseIf @OSVersion="WIN_2003" Then
        _EnumRegProcess6()
        _EnumRegProcess7()
        _EnumRegProcess8()
Else 
        MsgBox(0,"","抱歉,目前你的系统还不被支持!")
EndIf
$Lines=_FileCountLines(@ScriptDir&"\FixedPatchsList2.ini")
MsgBox(0,"行数",$Lines)
Func _EnumRegProcess1()
    While  1
            $i +=1
            $EnumResult=RegEnumKey($CommonReg,$i)
            If @error <> 0  Then  ExitLoop
            $KBString = StringRegExpReplace($EnumResult, '.*?(KB\d+)[^\d]*?.*', '$1')
                If @extended > 0 Then IniWrite(@ScriptDir&"\FixedPatchsList2.ini","已安装补丁列表",$KBString,"1")
    WEnd
EndFunc        
Func _EnumRegProcess2()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP0"
        _EnumRegProcess1()
EndFunc
Func _EnumRegProcess3()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP2"
        _EnumRegProcess1()
EndFunc
Func _EnumRegProcess4()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP3"
        _EnumRegProcess1()
EndFunc
Func _EnumRegProcess5()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP4"
        _EnumRegProcess1()
EndFunc
Func _EnumRegProcess6()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP10"
        _EnumRegProcess1()
EndFunc
Func _EnumRegProcess7()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP2"
        _EnumRegProcess1()
EndFunc
Func _EnumRegProcess8()
        $CommonReg="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\SP3"
        _EnumRegProcess1()
EndFunc
发表于 2010-9-25 16:50:58 | 显示全部楼层
回复 3# newuser
不太理解你的意思。
也不太明白补丁在注册表中的结构。
不过看你上面代码中大概有这个规律:
WINDOWS XP中是HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\XXX
WINDOWS 2003中是HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\XXX
以XP为例:为什么不枚举HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP下的子键,再判断呢?
发表于 2010-9-25 16:58:34 | 显示全部楼层
执行假死机?
newuser 发表于 2010-9-25 15:42



    死循环?
 楼主| 发表于 2010-9-25 16:59:34 | 显示全部楼层
回复 4# 3mile

sp0 sp1...就是windows xp下的子键啊!一楼的代码就是想象阁下说的那样,但没按照我的想法执行
发表于 2010-9-25 17:26:06 | 显示全部楼层
回复 6# newuser
#include <Array.au3>
#include <WinAPIEx.au3>

Local $hKey, $Count, $Num = 0
Local $Vkey = 'SOFTWARE\Microsoft\Updates\Windows XP'
Local $aKey
$array=EnumKey($Vkey)
_ArrayDisplay($array)
If UBound($array) > 0 Then
        For $i = 0 To UBound($array) - 1
                $Wkey = $Vkey & '\' & $aKey[$i]
                $keyArray=EnumKey($Wkey)
                _ArrayDisplay($keyArray)
                If UBound($keyArray)>0 Then
                        For $n=0 To UBound($keyArray)-1
                                IniWrite("hotfixed.ini","hotfixed",$keyArray[$n],"1")
                        Next
                EndIf
        Next
EndIf

Func EnumKey($Key)
        $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, $key)
        $Count = _WinAPI_RegQueryInfoKey($hKey)        
        Dim $aKey[$Count[0]]
        For $i = 0 To UBound($aKey) - 1
                $aKey[$i] = _WinAPI_RegEnumKey($hKey, $i)
        Next

        _WinAPI_RegCloseKey($hKey)

        If Not IsArray($aKey) Then
                Return -1
        Else
                Return $aKey
        EndIf
EndFunc   ;==>EnumKey

评分

参与人数 2金钱 +50 收起 理由
newuser + 30 能帮助注释吗?
afan + 20

查看全部评分

 楼主| 发表于 2010-9-26 07:45:15 | 显示全部楼层
本帖最后由 newuser 于 2010-9-26 07:48 编辑

回复 7# 3mile
谢谢!
 楼主| 发表于 2010-9-26 07:53:49 | 显示全部楼层
只枚举了SP0的KB,如图:

回复 7# 3mile

本帖子中包含更多资源

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

×
 楼主| 发表于 2010-9-26 08:38:02 | 显示全部楼层
回复 7# 3mile
第1轮循环进行完毕,但是在进入第2轮子循环,就没有全进行下去或者说没有进行完整?
#include <Array.au3>
#include <WinAPIEx.au3>
 
Local $hKey, $Count, $Num = 0
Local $Vkey = 'SOFTWARE\Microsoft\Updates\Windows Server 2003';第一好要枚举的父键
Local $aKey
$array=EnumKey($Vkey);首先定义了枚举的变量后在用函数枚举
_ArrayDisplay($array);显示返回的数组
If UBound($array) > 0 Then;如果返回的数组维度大于0
        For $i = 0 To UBound($array) - 1;从0 到 2
                $Wkey = $Vkey & '\' & $aKey[$i]
                                ;第1个$Wkey是:SOFTWARE\Microsoft\Updates\Windows Server 2003\SP10
                                ;可是 第1个再EnumKey()后,后续的$i=1和$i=2没进行?
                $keyArray=EnumKey($Wkey)
                                MsgBox(0,"第"&$i&"的UBound($keyArray)维度是",UBound($keyArray))
                _ArrayDisplay($keyArray)
                If UBound($keyArray)>0 Then
                        For $n=0 To UBound($keyArray)-1
                                IniWrite("hotfixed.ini","hotfixed",$keyArray[$n],"1")
                        Next
                EndIf
        Next
EndIf
 
Func EnumKey($Key)
        $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, $key)
                ;MsgBox(0,'$hKey',$hKey)
                ;打开指定的键的子键,父键:$HKEY_LOCAL_MACHINE,子键:$Key,它实际接受变量$Vkey的值
        $Count = _WinAPI_RegQueryInfoKey($hKey) ;检索指定键的相关信息,理解为$key下有多少项或其相关信息
                ;MsgBox(0,'$Count',$Count[0]&" "&$Count[1]&" "&$Count[2]&" "&$Count[3] )
        Dim $aKey[$Count[0]];第一一个一维数组,有三个元素
                ;MsgBox(0,'UBound($aKey)',UBound($aKey))
        For $i = 0 To UBound($aKey) - 1;$aKey数组的维度是3,数组下标确是从0 到 2
                $aKey[$i] = _WinAPI_RegEnumKey($hKey, $i);枚举指定打开键下的子键
                                MsgBox(0,"第"&$i&"个枚举信息",$aKey[$i])
        Next
 
        _WinAPI_RegCloseKey($hKey);关闭打开的键
 
        If Not IsArray($aKey) Then
                Return -1;如果$aKey不是数组,返回值 -1
        Else
                Return $aKey;返回指定的数组
        EndIf
EndFunc   ;==>EnumKey
发表于 2010-9-26 10:57:32 | 显示全部楼层
回复 10# newuser
第11行的问题。
#include <Array.au3>
#include <WinAPIEx.au3>
 
Local $hKey, $Count, $Num = 0
Local $Vkey = 'SOFTWARE\Microsoft\Updates\Windows Server 2003';第一好要枚举的父键
Local $aKey
$array=EnumKey($Vkey);首先定义了枚举的变量后在用函数枚举
_ArrayDisplay($array);显示返回的数组
If UBound($array) > 0 Then;如果返回的数组维度大于0
        For $i = 0 To UBound($array) - 1;从0 到 2
                $Wkey = $Vkey & '\' & $array[$i]
                                ;第1个$Wkey是:SOFTWARE\Microsoft\Updates\Windows Server 2003\SP10
                                ;可是 第1个再EnumKey()后,后续的$i=1和$i=2没进行?
                $keyArray=EnumKey($Wkey)
                                MsgBox(0,"第"&$i&"的UBound($keyArray)维度是",UBound($keyArray))
                _ArrayDisplay($keyArray)
                If UBound($keyArray)>0 Then
                        For $n=0 To UBound($keyArray)-1
                                IniWrite("hotfixed.ini","hotfixed",$keyArray[$n],"1")
                        Next
                EndIf
        Next
EndIf
 
Func EnumKey($Key)
        $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, $key)
                ;MsgBox(0,'$hKey',$hKey)
                ;打开指定的键的子键,父键:$HKEY_LOCAL_MACHINE,子键:$Key,它实际接受变量$Vkey的值
        $Count = _WinAPI_RegQueryInfoKey($hKey) ;检索指定键的相关信息,理解为$key下有多少项或其相关信息
                ;MsgBox(0,'$Count',$Count[0]&" "&$Count[1]&" "&$Count[2]&" "&$Count[3] )
        Dim $aKey[$Count[0]];第一一个一维数组,有三个元素
                ;MsgBox(0,'UBound($aKey)',UBound($aKey))
        For $i = 0 To UBound($aKey) - 1;$aKey数组的维度是3,数组下标确是从0 到 2
                $aKey[$i] = _WinAPI_RegEnumKey($hKey, $i);枚举指定打开键下的子键
                                MsgBox(0,"第"&$i&"个枚举信息",$aKey[$i])
        Next
 
        _WinAPI_RegCloseKey($hKey);关闭打开的键
 
        If Not IsArray($aKey) Then
                Return -1;如果$aKey不是数组,返回值 -1
        Else
                Return $aKey;返回指定的数组
        EndIf
EndFunc   ;==>EnumKey

评分

参与人数 3金钱 +80 收起 理由
zps26 + 30
newuser + 30 我只看表不懂里,哎!谢谢!
afan + 20

查看全部评分

 楼主| 发表于 2010-9-26 17:26:52 | 显示全部楼层
我在同事的计算机测试,出现以下错误!

本帖子中包含更多资源

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

×
发表于 2010-9-26 19:15:02 | 显示全部楼层
回复 12# newuser
晕,包含文件啊。
WINAPIex.AU3
 楼主| 发表于 2010-9-27 07:22:21 | 显示全部楼层
回复 11# 3mile
在同事的计算机上出现了:数组变量格式错误.
问题应该是这行: Dim $aKey[$Count[0]],
但是在我的计算机上怎么好使!
发表于 2010-9-27 09:21:44 | 显示全部楼层
回复 14# newuser
如果确定是这一句 Dim $aKey[$Count[0]]
那么应该是$Count[0]出错,也就是说前一行$Count = _WinAPI_RegQueryInfoKey($hKey)并未取得子键数目。
两种可能:1、键不存在,即$Count返回空值。
2、可能性极大的是:包含文件WINAPIEX.AU3文件在你同事的机器上没有。于是出现上图的错误,继续执行的话$Count = _WinAPI_RegQueryInfoKey($hKey)这行返回错误代码或未执行。
解决办法:复制WINAPIEX.AU3文件到你同事机器上。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-12 21:01 , Processed in 0.097787 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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