newuser 发表于 2010-9-26 14:07:39

inwrite()写文件的问题?

本帖最后由 newuser 于 2010-9-27 10:36 编辑

我的错,无须做多余的判断,如果相同不会写上,不过看代码也可以执行啊?总感觉写的信息少了呀!
_EnumFixedPatchsInReg2()没执行?而且感觉_EnumFixedPatchsInReg()也有问题,但找不着?#include <GuiListView.au3>
#include <GUIListBox.au3>
#include <GuiStatusBar.au3>;定义窗口底步状态条
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPIEx.au3>
#include <file.au3>;_FileListToArray()用


Dim $NewPatchsList = @ScriptDir & "\NewList.ini", $FixedPatchsList = @ScriptDir & "\FixedList.ini"
Dim $Update = @ScriptDir & "\Update", $BackUpdate = @ScriptDir & "\BackUpdate"
Dim $NewMessage = @ScriptDir & "\NewUpdate.txt";网站有补丁更新进行消息提示
;Dim$WebList=@ScriptDir&"\WebList.ini"
Dim $PingState
Dim $EnumRegPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\HotFix"
Dim $EnumRegPath2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Dim $EnumResult;接收枚举信息
Dim $i
Dim $oIE, $oLinks, $iNumLinks
Dim $Num, $j = 1;$j表示在ListView中补丁序列号
Dim $filelist, $Folder;用于手动修复
Dim $file;在拆分网页连接地址用
Dim $Bar = ;用于定义窗口任务栏
Dim $f_tryAttach, $f_visible;用于隐藏打开的浏览器窗口用
;------以下变量在枚举HKEY\SOFTWARE\Microsoft\Update用,生成hotfixed.ini文件
Local $hKey;定义子键用$hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, $key)
Local $Count ;检索用 $Count = _WinAPI_RegQueryInfoKey($hKey)
Local $Vkey = 'SOFTWARE\Microsoft\Updates\Windows Server 2003';第一好要枚举的父键
Local $aKey
;-----------对hotfixed.ini筛选KB 时用
Dim $array, $str
;-----========================
If @OSVersion = "WIN_2003" Then
        $oIE = _IECreate("http://10.64.240.23:801/clientfixpatchs_2003.htm")
        $Vkey = 'SOFTWARE\Microsoft\Updates\Windows Server 2003';第一好要枚举的父键
ElseIf @OSVersion = "WIN_XP" Then
        $oIE = _IECreate("http://10.64.240.23:801/clientfixpatchs_XP.htm")
        $Vkey = 'SOFTWARE\Microsoft\Updates\Windows XP';第一好要枚举的父键
Else
        MsgBox(0, "", "抱歉!目前本工具仅支持WIN_XP和WinServer2003系统,程序正在退出...")
EndIf
If FileExists($FixedPatchsList) Or FileExists(@ScriptDir&'\hotfixed.ini') Then
        FileDelete($FixedPatchsList)
        FileDelete(@ScriptDir&'\hotfixed.ini')
EndIf
_EnumFixedPatchsInReg3()
MsgBox(0,'hotfixed.ini内容',_FileCountLines(@ScriptDir&'\hotfixed.ini'))
_FilterEnumFixedPatchsInReg3();筛选_EnumFixedPatchsInReg3()生成的hotfixed.ini文件的KB部分并写入到FixedList.ini
MsgBox(0,'第1次生成的FixedList.ini的内容',_FileCountLines($FixedPatchsList))
_EnumFixedPatchsInReg()
MsgBox(0,'第2次生成的FixedList.ini的内容',_FileCountLines($FixedPatchsList))
_EnumFixedPatchsInReg2()
MsgBox(0,'第3次生成的FixedList.ini的内容',_FileCountLines($FixedPatchsList))
Func _EnumFixedPatchsInReg3()
        $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
EndFunc   ;==>_EnumFixedPatchsInReg3
Func _FilterEnumFixedPatchsInReg3()
        $array = IniReadSection(@ScriptDir & '\hotfixed.ini', 'hotfixed')
        If @error Then
                Exit
        Else
                For $i = 1 To $array
                        $str = String($array[$i])
                        If StringInStr($str, "KB") Then
                                IniWrite($FixedPatchsList, '已经安装的补丁', $array[$i], '1')
                        Else
                        EndIf
                Next
        EndIf
EndFunc   ;==>_FilterEnumFixedPatchsInReg3

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&" "&$Count&" "&$Count&" "&$Count )
        Dim $aKey[$Count];第一一个一维数组,有三个元素
        ;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
Func _EnumFixedPatchsInReg();从注册表枚举已经修复的补丁并把它们的名称写入到FixedList.ini文件中
        While 1
                $i += 1;已修复补丁枚举起始点,在定义区有定义
                $EnumResult = RegEnumKey($EnumRegPath, $i)
                If @error <> 0 Then ExitLoop
                $array=IniReadSection($FixedPatchsList,'已经安装的补丁')
                If @error Then
                Exit
      Else
                        For $i=1 To $array
                  $str=String($array[$i])
                  If StringInStr($str,$EnumResult) Then
                          
                        Else
                                IniWrite($FixedPatchsList,'已经安装的补丁',$EnumResult,'1')
                  EndIf
                Next
                EndIf
        WEnd
EndFunc   ;==>_EnumFixedPatchsInReg
Func _EnumFixedPatchsInReg2()
        While 1
                $i += 1
                $var = RegEnumKey($EnumRegPath2, $i)
                If @error <> 0 Then ExitLoop
                $KBString = StringRegExpReplace($var, '.*?(KB\d+)[^\d]*?.*', '$1');如何让它只提KB部分?
                If @extended > 0 Then
                  $array=IniReadSection($FixedPatchsList,'已经安装的补丁')
                        If @error Then
                    Exit
            Else
                          For $i=1 To $array
                            $str=String($array[$i])
                                  If StringInStr($str,$KBString) Then
                                       
                                  Else
                                    IniWrite($FixedPatchsList, "已经安装的补丁", $KBString, "1")
                                  EndIf
                                Next
                        EndIf
                EndIf
        WEnd
EndFunc   ;==>_EnumFixedPatchsInReg2

hzxymkb 发表于 2010-9-26 22:09:32

楼主最好能修改一下标题!谢谢!{:face (301):}

newuser 发表于 2010-9-27 10:37:25

回复 2# hzxymkb
抱歉,代码的标题不是很确定,暂定为inwrite()写文件的问题吧!希望老大帮忙看看!
页: [1]
查看完整版本: inwrite()写文件的问题?