#include <GUIConstants.au3> #Include <File.au3> AutoItSetOption("TrayIconHide", 1) ;скрыть в системной панели индикатор AutoIt Global $regfile = @ScriptDir&'\regbak.reg' Global $aRecords $tempfile=@TempDir&'\temporarily.reg' $x=0 $razdelit='#==========================' $del=1 $Text='' If Not FileExists($regfile) Then $regfile = FileOpenDialog("Выбор файла *.reg, для которого будет выполнен бэкап.", @ScriptDir & "", "reg-файл (*.reg)", 1 + 4 ) If @error Then Exit EndIf EndIf $filename="backup_"&@YEAR&"."&@MON&"."&@MDAY&"_"&@HOUR&"."&@MIN&"."&@SEC&'.reg' ; имя бэкап-файла $filebackup = FileOpen(@ScriptDir&'\'&$filename, 1) ; открываем бэкап-файл If $del=1 Then $delfile = FileOpen(@ScriptDir&'\del_'&$filename, 1) FileWrite($delfile, 'Введите правильный заголовок для этого reg-файла и он удалит в реестре указанные здесь ветки'&@CRLF&@CRLF) ; выполняем копирование оригинала в темп и удаляем пустые секции в reg-файле FileCopy($regfile, @TempDir,1) $aRegfile = StringRegExp($regfile, "(^.*)\\(.*)$", 3) $regfile=@TempDir&'\'&$aRegfile[1] _IniDeleteEmptySections($regfile) ; читаем рег-файл в массив построчно If Not _FileReadToArray($regfile,$aRecords) Then MsgBox(4096,"Ошибка", "Ошибка чтения массива", @error) Exit EndIf ;MsgBox(0, "Проверка", $aRecords[0]) For $i=1 To $aRecords[0] ; определяем валидность строки в элементе массива If StringLeft($aRecords[$i], 3)='[HK' Then $temporarily = StringTrimLeft($aRecords[$i], 1) $temporarily = StringTrimRight($temporarily, 1) If StringInStr($Text,$aRecords[$i])<>0 Then ContinueLoop If $del=1 Then FileWrite($delfile, '[-'&$temporarily&']'&@CRLF) ;MsgBox(0, "Проверка", $temporarily) ; проверка существования ветки $reg1 = RegRead($temporarily, "") If @error=1 Then ContinueLoop Else $x+=1 ;счётчик нужен чтобы при первом запуске добавилась строка "Windows Registry Editor Version 5.00" в начало открытого файла RunWait ( @Comspec&' /C reg export "'&$temporarily&'" "'&$tempfile&'"', '', @SW_HIDE ) $vr = FileOpen($tempfile, 0) $vr1 = FileRead($vr) If $x=1 Then FileWrite($filebackup, $vr1&@CRLF&@CRLF) Else $vr1 = StringReplace($vr1, "Windows Registry Editor Version 5.00"&@CRLF, $razdelit) $vr1 = StringReplace($vr1, "REGEDIT4"&@CRLF, $razdelit) FileWrite($filebackup, $vr1&@CRLF&@CRLF) EndIf FileClose($vr) $Text &= '['&$temporarily&']'&@CRLF ;добавляем строку в переменную для проверки и исключения повторов ;MsgBox(0, "Проверка", $Text) EndIf EndIf Next If $del=1 Then FileClose($delfile) FileWrite($filebackup, @CRLF) FileClose($filebackup) ;если файл пустой, то удаляем его. Добавляется две строки и пустой файл равен двум байтам. If FileGetSize(@ScriptDir&'\'&$filename)=2 Then FileDelete(@ScriptDir&'\'&$filename) If $del=1 Then If FileGetSize(@ScriptDir&'\del_'&$filename)=0 Then FileDelete(@ScriptDir&'\del_'&$filename) EndIf ; функция для удаления пустых секций в reg-файле Func _IniDeleteEmptySections($sIniFile) Local $aSections = IniReadSectionNames($sIniFile) If @error Then Return SetError(1, 0, 0) For $i = 1 To UBound($aSections)-1 IniReadSection($sIniFile, $aSections[$i]) If @error = 1 Then IniDelete($sIniFile, $aSections[$i]) Next Return 1 EndFunc |