none
Como inserir informações no registro do Windows utilizando arquivos .vbs RRS feed

  • Pergunta

  • Pessoal,

    Eu tenho este script que informa o GUID e o SID de um usuário e preciso inserir no registro as informações que são exibidas e outras informações que validem via registro o perfil do usuário. Dessa forma, poderei realizar o backup do perfil do usuário sem que seja preciso que ele realize o logon na estação nova. Eu teria apenas que entregá-la e ele logaria e todo o perfil anterior dele estaria configurado como antes.

    Segue o script.

    Set obj = GetObject("LDAP://CN=LOGIN,CN=Users,DC=MEUDOMINIO,DC=COM")

    Wscript.Echo "User: " & obj.Get("samaccountname") & " - " & obj.Get("DisplayName")
    Wscript.Echo "GUID: " & ConvertHexStringGUIDToStringGUID(obj.GUID)
    Wscript.Echo "SID:  " & HexSIDToDec(OctetToHexStr(obj.Get("objectsid")))

    ' Retrieve the value of the objectSID attribute as a byte array.
    ' arrbytSID = obj.Get("objectsid")

    ' Convert byte array to hex string.
    ' strHexSID = OctetToHexStr(arrbytSID)
    ' Wscript.Echo "OctetToHexStr: " & strHexSID

    ' Convert hex SID values to decimal format.
    ' strDecSID = HexSIDToDec(strHexSID)
    ' Wscript.Echo "HexSIDToDec(strHexSID): " & strDecSID

    set obj = nothing


    '================================================================
    ' ConvertHexStringGUIDToStringGUID function
    '================================================================
    Function ConvertHexStringGUIDToStringGUID(strOctet)
        Dim tmpGUID, GUIDStr
        'Convert the string by flipping the bits around.
        GUIDStr = Mid(strOctet, 7, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  5, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  3, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  1, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 11, 2)
        GUIDStr = GUIDStr + Mid(strOctet,  9, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 15, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 13, 2)
        GUIDStr = GUIDStr + Mid(strOctet, 17, Len(strOctet))

        tmpGUID = "{" & Mid(GUIDStr,  1,  8) & "-" & Mid(GUIDStr,  9, 4) & _
                  "-" & Mid(GUIDStr, 13,  4) & "-" & Mid(GUIDStr, 17, 4) & _
                  "-" & Mid(GUIDStr, 21, 15) & "}"

        ConvertHexStringGUIDToStringGUID = tmpGUID
    End Function



    Function OctetToHexStr(ByVal arrbytOctet)
        ' Function to convert OctetString (byte array) to Hex string.

        Dim k

        OctetToHexStr = ""
        For k = 1 To Lenb(arrbytOctet)
            OctetToHexStr = OctetToHexStr _
                & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
        Next

    End Function



    Function HexSIDToDec(ByVal strSID)
        ' Function to convert most hex SID values to decimal format.

        Dim arrbytSID, lngTemp, j

        ReDim arrbytSID(Len(strSID)/2 - 1)
        For j = 0 To UBound(arrbytSID)
            arrbytSID(j) = CInt("&H" & Mid(strSID, 2*j + 1, 2))
        Next

        If (UBound(arrbytSID) = 11) Then
            HexSIDToDec = "S-" & arrbytSID(0) & "-" _
                & arrbytSID(1) & "-" & arrbytSID(8)

            Exit Function
        End If

        If (UBound(arrbytSID) = 15) Then
            HexSIDToDec = "S-" & arrbytSID(0) & "-" _
                & arrbytSID(1) & "-" & arrbytSID(8)

            lngTemp = arrbytSID(15)
            lngTemp = lngTemp * 256 + arrbytSID(14)
            lngTemp = lngTemp * 256 + arrbytSID(13)
            lngTemp = lngTemp * 256 + arrbytSID(12)

            HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

            Exit Function
        End If

        HexSIDToDec = "S-" & arrbytSID(0) & "-" _
            & arrbytSID(1) & "-" & arrbytSID(8)

        lngTemp = arrbytSID(15)
        lngTemp = lngTemp * 256 + arrbytSID(14)
        lngTemp = lngTemp * 256 + arrbytSID(13)
        lngTemp = lngTemp * 256 + arrbytSID(12)

        HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

        lngTemp = arrbytSID(19)
        lngTemp = lngTemp * 256 + arrbytSID(18)
        lngTemp = lngTemp * 256 + arrbytSID(17)
        lngTemp = lngTemp * 256 + arrbytSID(16)

        HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

        lngTemp = arrbytSID(23)
        lngTemp = lngTemp * 256 + arrbytSID(22)
        lngTemp = lngTemp * 256 + arrbytSID(21)
        lngTemp = lngTemp * 256 + arrbytSID(20)

        HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

        If (UBound(arrbytSID) > 23) Then
            lngTemp = arrbytSID(27)
            lngTemp = lngTemp * 256 + arrbytSID(26)
            lngTemp = lngTemp * 256 + arrbytSID(25)
            lngTemp = lngTemp * 256 + arrbytSID(24)

            HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
        End If

    End Function

    Este script deveria solicitar o login e permitir inserir as informações no registro, mas eu não entendo nada de VBS.

    Alguém pode me orientar em como incrementar este script?

    quinta-feira, 19 de janeiro de 2017 18:26