1. Tải bản cài đặt AutoIT mới nhất

    Chào Khách. Nếu bạn mới tham gia và chưa cài đặt AutoIT.
    Vui lòng vào topic trên để tải bản AutoIT mới nhất nhé
    Dismiss Notice
  2. Quy định và nội quy

    Chào Khách. Vui lòng đọc kỹ nội quy và quy định của diễn đàn
    Để tránh bị ban một cách đáng tiếc nhé!
    Dismiss Notice
  3. Hướng dẫn chèn mã AutoIT trong diễn đàn

    Chào Khách. Vui lòng xem qua bài viết này
    Để biết cách chèn mã AutoIT trong diễn đàn bạn nhé :)
    Dismiss Notice

Download REG to AU3

Thảo luận trong 'Cài đặt AutoIt - Tool hỗ trợ AutoIt' bắt đầu bởi Trong, 17/11/15.

  1. Trong

    Trong Thành viên
    • 18/23

    Tham gia ngày:
    4/11/15
    Bài viết:
    23
    Đã được thích:
    85
    Nơi ở:
    Hà Nội
    Công cụ giúp chuyển đổi nhanh tập tin Registration Entries (.reg) sang AutoItScript (.au3)
    Hỗ trợ kéo thả các tập tin vào GUI hoặc EXE và có nút chọn file.

    [​IMG]

    Mã (AutoIt):

    ; some hex Types of Registry Values
    ;hex: REG_BINARY
    ;hex(0): REG_NONE                            - Null value
    ;hex(1): REG_SZ                                *- Null terminated Unicode fixed string value
    ;hex(2): EXPAND_SZ                            - Null terminated unexpanded Unicode/ANSI environment string value
    ;hex(3): REG_BINARY                            *- Binary value of any form/length
    ;hex(4): REG_DWORD                            *- 32-bit numerical value
    ;hex(4): REG_DWORD_LITTLE_ENDIAN             *- little-endian 32-bit numerical value (same as REG_DWORD)
    ;hex(5): REG_DWORD_BIG_ENDIAN                *- 32-bit reversed numerical value
    ;hex(6): REG_LINK                            *- Symbolic Unicode link string value
    ;hex(7): REG_MULTI_SZ                        - Array of multiple Unicode strings separated/ended by null characters
    ;hex(8): REG_RESOURCE_LIST                    *- Device driver list of hardware resources in Resource Map tree
    ;hex(9): REG_FULL_RESOURCE_DESCRIPTOR        *- List of hardware resources in Description tree
    ;hex(a): REG_RESOURCE_REQUIREMENTS_LIST        *- Device driver list of hardware resource requirements in Resource Map tree
    ;hex(?): REG_QWORD                            *- 64-bit numerical value
    ;hex(?): REG_QWORD_LITTLE_ENDIAN             *- little-endian 64-bit numerical value (same as REG_QWORD)


    ;~ _REGtoAU3(@ScriptDir & "\RegTest.reg")
    ; * -----:|
    Func _REGtoAU3($sFileIN, $sFileOUT = "", $ShortKeys = 0)
        If Not FileExists($sFileIN) Then Return SetError(1, 0, 0)
        If $sFileOUT = "" Or $sFileOUT = Default Or $sFileOUT = -1 Then $sFileOUT = $sFileIN & ".au3"
        If FileGetSize($sFileIN) = 0 Then Return SetError(1, "source-file is empty.", 0)
        Local $hFileIN = FileOpen($sFileIN, 0)
        If $hFileIN = -1 Then Return SetError(2, "Unable to open source-file.", 0)
        Local $hFileOut = FileOpen($sFileOUT, 2 + 8)
        If $hFileOut = -1 Then
            If $hFileIN Then FileClose($hFileIN)
            Return SetError(3, "Unable to open destinaion-file.", 0)
        EndIf
        Local $cLine, $LinesRead = 0, $Step = 0, $EOF = 0, $RegEditV = 0, $Error = 0, $xPos = 0, $ESC = 0, $Write = 0
        Local $REG_Delete = 0, $REG_KEY = "", $REG_ValueName = "", $REG_Type = "", $REG_Value = ""
        While 1
            $cLine = _R2A_ReadLineFile($hFileIN, $EOF)
            $LinesRead = $LinesRead + 1
            Select
                Case $EOF And $cLine = ""
                    If $Step = 1 Then
                        $Write = _R2A_CommandLine($REG_Delete, $REG_KEY, $REG_ValueName, $REG_Type, $REG_Value, $hFileOut)
                        If @error Then Return SetError(4, "Unable to write to Output! ", 0)
                    EndIf
                    ExitLoop
                Case $cLine = ""
                Case $RegEditV = 0
                    If $cLine = "REGEDIT4" Then $RegEditV = 4
                    If $cLine = "Windows Registry Editor Version 5.00" Then $RegEditV = 5
                Case StringLeft($cLine, 1) = "[" And StringRight($cLine, 1) = "]"
                    $REG_ValueName = ""
                    $REG_Type = ""
                    $REG_Value = ""
                    If $ShortKeys Then
                        $cLine = StringReplace($cLine, "[HKEY_LOCAL_MACHINE", "[HKLM")
                        $cLine = StringReplace($cLine, "[HKEY_CLASSES_ROOT", "[HKCR")
                        $cLine = StringReplace($cLine, "[HKEY_CURRENT_USER", "[HKCU")
                        $cLine = StringReplace($cLine, "[HKEY_USERS", "[HKU")
                        $cLine = StringReplace($cLine, "[HKEY_CURRENT_CONFIG", "[HKCC")
                    EndIf
                    $cLine = StringTrimRight(StringTrimLeft($cLine, 1), 1)
                    If $Step = 1 Then
                        If StringInStr($cLine, $REG_KEY) = 0 Then
                            $Write = _R2A_CommandLine($REG_Delete, $REG_KEY, $REG_ValueName, $REG_Type, $REG_Value, $hFileOut)
                            If @error Then Return SetError(4, "Unable to write to Output! ", 0)
                        EndIf
                    EndIf
                    $REG_KEY = $cLine
                    If StringLeft($REG_KEY, 1) = "-" Then
                        $REG_Delete = 1
                        $REG_KEY = StringTrimLeft($REG_KEY, 1)
                        $Write = _R2A_CommandLine($REG_Delete, $REG_KEY, $REG_ValueName, $REG_Type, $REG_Value, $hFileOut)
                        If @error Then Return SetError(4, "Unable to write to Output! ", 0)
                        $Step = 0
                    Else
                        $Step = 1
                    EndIf
                Case $Step < 1
                Case Else
                    $Step = 2
                    $Error = 0
                    If StringLeft($cLine, 2) = "@=" Then
                        $REG_ValueName = "@"
                        $cLine = StringTrimLeft($cLine, 2)
                        If $cLine = "-" Then $Error = 1
                    ElseIf StringLeft($cLine, 1) = '"' Then
                        $xPos = 0
                        $ESC = 0
                        $REG_ValueName = ""
                        For $R2A_i = 1 To StringLen($cLine)
                            Local $lBreak = StringMid($cLine, $R2A_i, 1)
                            Select
                                Case $ESC
                                    $ESC = 0
                                    $REG_ValueName = $REG_ValueName & $lBreak
                                Case $lBreak = '\'
                                    $ESC = 1
                                Case $lBreak = '"'
                                    If $R2A_i > 1 Then
                                        $xPos = $R2A_i + 1
                                        ExitLoop
                                    EndIf
                                Case Else
                                    $REG_ValueName = $REG_ValueName & $lBreak
                            EndSelect
                        Next
                        If StringMid($cLine, $xPos, 1) = "=" Then
                            $cLine = StringTrimLeft($cLine, $xPos)
                        Else
                            $Error = 2
                        EndIf
                    Else
                        $Error = 3
                    EndIf
                    If $Error Then
                        ConsoleWrite("REG to AU3 - Warning " & $Error & ": Bad syntax at value-name in line: " & $LinesRead & @CRLF)
                        ContinueLoop
                    EndIf
                    If StringLeft($cLine, 1) = '"' And StringRight($cLine, 1) = '"' Then
                        $REG_Type = "REG_SZ"
                        $xPos = 0
                        $ESC = 0
                        $REG_Value = ""
                        For $R2A_i = 1 To StringLen($cLine)
                            Local $lBreak = StringMid($cLine, $R2A_i, 1)
                            Select
                                Case $ESC
                                    $ESC = 0
                                    $REG_Value = $REG_Value & $lBreak
                                Case $lBreak = '\'
                                    $ESC = 1
                                Case $lBreak = '"'
                                    If $R2A_i > 1 Then
                                        $xPos = $R2A_i + 1
                                        ExitLoop
                                    EndIf
                                Case Else
                                    $REG_Value = $REG_Value & $lBreak
                            EndSelect
                        Next
                    ElseIf StringLeft($cLine, 1) = "-" Then
                        $REG_Delete = 1
                    Else
                        Local $sType = StringLeft($cLine, StringInStr($cLine, ":"))
                        $cLine = StringTrimLeft($cLine, StringLen($sType))
                        Select
                            Case $sType = "dword:"
                                $REG_Type = "REG_DWORD"
                                $REG_Value = Dec($cLine)
                            Case $sType = "hex(7):"
                                $REG_Type = "REG_MULTI_SZ"
                                $REG_Value = _R2A_Hex2String($cLine, $RegEditV)
                            Case $sType = "hex(2):"
                                $REG_Type = "REG_EXPAND_SZ"
                                $REG_Value = _R2A_Hex2String($cLine, $RegEditV)
                            Case $sType = "hex(0):"
                                $REG_Type = "REG_NONE"
                                $REG_Value = StringReplace($cLine, ",", "")
                            Case $sType = "hex:"
                                $REG_Type = "REG_BINARY"
                                $REG_Value = StringReplace($cLine, ",", "")
                            Case StringLeft($sType, 3) = "hex"
                                ConsoleWrite("REG to AU3 - Warning: unsupported key-type: " & $sType & "  - in line: " & $LinesRead & @CRLF)
                                ContinueLoop
                            Case Else
                                ConsoleWrite("REG to AU3 - Warning: bad syntax at key-type in line: " & $LinesRead & @CRLF)
                                ContinueLoop
                        EndSelect
                    EndIf
                    $Write = _R2A_CommandLine($REG_Delete, $REG_KEY, $REG_ValueName, $REG_Type, $REG_Value, $hFileOut)
                    If @error Then Return SetError(4, "Unable to write to Output! ", 0)
            EndSelect
        WEnd
        If $hFileIN Then FileClose($hFileIN)
        If $hFileOut Then FileClose($hFileOut)
        If FileGetSize($sFileOUT) = 0 Then FileDelete($sFileOUT)
        Sleep(10)
        Return SetError(0, 0, 1)
    EndFunc   ;==>_REGtoAU3
    ; * -----:|
    Func _R2A_ReadLineFile($hFileIN, ByRef $EOF)
        Local $cLine = "", $cContinue = 1, $nBreak, $cBreak, $cRead
        While $cContinue
            $cContinue = 0
            $cRead = ""
            While 1
                $nBreak = FileRead($hFileIN, 1)
                If @error = -1 Then
                    $EOF = 1
                    ExitLoop
                EndIf
                $cBreak = Asc($nBreak)
                If $cBreak > 0 And $cBreak < 254 Then $cRead = $cRead & $nBreak
                If $cBreak = 10 Then ExitLoop
            WEnd
            $cRead = StringStripWS($cRead, 3)
            If StringRight($cRead, 1) = "\" Then
                $cRead = StringTrimRight($cRead, 1)
                $cContinue = 1
            EndIf
            $cLine = $cLine & $cRead
        WEnd
        Return SetError(0, 0, $cLine)
    EndFunc   ;==>_R2A_ReadLineFile
    ; * -----:|
    Func _R2A_CleanString($sVal)
        $sVal = StringReplace($sVal, '"', '""')
        $sVal = StringReplace($sVal, @LF, '" & @LF & "')
        Return SetError(0, 0, $sVal)
    EndFunc   ;==>_R2A_CleanString
    ; * -----:|
    Func _R2A_Hex2String($HexIN, $RegEditV)
        Local $i, $vChar, $StringOUT = ""
        If $RegEditV <> 4 Then $RegEditV = 5
        For $i = 1 To StringLen($HexIN)
            $vChar = Chr(Dec(StringMid($HexIN, $i, 2)))
            If $vChar = Chr(0) Then $vChar = @LF
            $StringOUT = $StringOUT & $vChar
            If $RegEditV = 5 Then
                $i = $i + 5
            Else
                $i = $i + 2
            EndIf
        Next
        While StringRight($StringOUT, 1) = @LF
            $StringOUT = StringTrimRight($StringOUT, 1)
        WEnd
        Return SetError(0, 0, $StringOUT)
    EndFunc   ;==>_R2A_Hex2String
    ; * -----:|
    Func _R2A_CommandLine(ByRef $REG_Delete, ByRef $REG_KEY, ByRef $REG_ValueName, ByRef $REG_Type, ByRef $REG_Value, $hFileOut)
        Local $cCommand
        If $REG_Delete Then
            $cCommand = "RegDelete(" & Chr(34) & _R2A_CleanString($REG_KEY) & Chr(34)
            If $REG_ValueName <> "" Then
                $cCommand = $cCommand & ", " & Chr(34) & _R2A_CleanString($REG_ValueName) & Chr(34)
            Else
                $REG_KEY = ""
            EndIf
            $cCommand = $cCommand & ")"
            $REG_Delete = 0
        Else
            $cCommand = "RegWrite(" & Chr(34) & _R2A_CleanString($REG_KEY) & Chr(34)
            If $REG_ValueName <> "" Then
                If $REG_ValueName = "@" Then $REG_ValueName = ""
                $cCommand = $cCommand & ", " & Chr(34) & _R2A_CleanString($REG_ValueName) & Chr(34)
                $cCommand = $cCommand & ", " & Chr(34) & $REG_Type & Chr(34)
                $cCommand = $cCommand & ", " & Chr(34) & _R2A_CleanString($REG_Value) & Chr(34)
            EndIf
            $cCommand = $cCommand & ")"
        EndIf
        $REG_ValueName = ""
        $REG_Type = ""
        $REG_Value = ""
        Local $Write = _R2A_WriteOutFile($cCommand, $hFileOut)
        If @error Then Return SetError(1, 0, 0)
        Return SetError(0, 0, 1)
    EndFunc   ;==>_R2A_CommandLine
    ; * -----:|
    Func _R2A_WriteOutFile($vLine, $hFileOut)
        If StringInStr($vLine, '"REG_NONE",') Then $vLine = ";" & $vLine
        If StringInStr($vLine, '"REG_BINARY",') Then
            $vLine = StringReplace($vLine, '"REG_BINARY", "', '"REG_BINARY", Binary("0x')
            $vLine = StringReplace($vLine, '")', '"))')
        EndIf
        If StringInStr($vLine, '"REG_DWORD",') Then
            $vLine = StringReplace($vLine, '"REG_DWORD", "', '"REG_DWORD", ')
            $vLine = StringReplace($vLine, '")', ')')
        EndIf
        Local $WriteFile = FileWriteLine($hFileOut, $vLine)
        If $WriteFile = 0 Then Return SetError(1, 0, 0)
        Return SetError(0, 0, 1)
    EndFunc   ;==>_R2A_WriteOutFile
    ; * -----:|
    [​IMG]
    Tải về:
     
    Chỉnh sửa cuối: 17/11/15
    tranchi3, Cam Nam, Phan Dong and 4 others like this.
  2. smaller759

    smaller759 Thành viên mới
    • 3/6

    Tham gia ngày:
    11/12/15
    Bài viết:
    6
    Đã được thích:
    13
    thanks bạn đã chia sẻ
     
    kamsamita1 and Phan Dong like this.
  3. luzk

    luzk Thành viên mới
    • 1/6

    Tham gia ngày:
    16/1/16
    Bài viết:
    2
    Đã được thích:
    4
    cám ơn sự chia sẻ của bạn nhé =))
     
    kamsamita1 and Phan Dong like this.
  4. PMHCT

    PMHCT Thành viên mới
    • 3/6

    Tham gia ngày:
    16/9/16
    Bài viết:
    8
    Đã được thích:
    7
    Nơi ở:
    MS-DOS A:\
    Không tìm thấy file rồi bạn :)
     
    kamsamita1 thích bài này.
  5. essered

    essered Thành viên
    • 18/23

    Tham gia ngày:
    11/9/16
    Bài viết:
    47
    Đã được thích:
    45
    thì bác copy code ra file .au3
     
    kamsamita1 and Huân Hoàng like this.
  6. dvhtrung

    dvhtrung Thành viên mới
    • 1/6

    Tham gia ngày:
    15/7/17
    Bài viết:
    11
    Đã được thích:
    0
    có vẽ hay nhỉ
     

Chia sẻ trang này

Đang tải...