Article ID: 325648 - Last Review: June 29, 2004 - Revision: 2.2

How To Convert a String Formatted GUID to a Hexadecimal String Form For Use When Querying the Active Directory

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q325648
Expand all | Collapse all

SUMMARY

This article describes how to convert a string formatted GUID (for example, {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}) to its hexdecimal string form for use in a GUID bind string in the Active Directory.

To convert a string formatted GUID to its hexadecimal string form, follow these steps:
  1. Paste the following code into a .vbs file.
    
    '================================================================
    ' Replace the value of strGUID with an actual GUID
    '================================================================
    strGUID = "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" 
    Set obj = GetObject("LDAP://<GUID=" & ConvertStringGUIDToHexStringGUID(strGUID) & ">")
    MsgBox "The octet guid for " & obj.Get("displayname") & " is " & obj.GUID
    
    '================================================================
    ' ConvertGUIDtoOCTET function
    '================================================================
    Function ConvertStringGUIDToHexStringGUID(strGUID)
        Dim octetStr, tmpGUID
    
        For i = 0 To Len(strGUID)
            t = Mid(strGUID, i + 1, 1)
            Select Case t
                Case "{"
                Case "}"
                Case "-"
                Case Else
                    tmpGUID = tmpGUID + t
            End Select
        Next
    
        octetStr = Mid(tmpGUID, 7, 2)             ' 0
        octetStr = octetStr + Mid(tmpGUID,  5, 2) ' 1
        octetStr = octetStr + Mid(tmpGUID,  3, 2) ' 2
        octetStr = octetStr + Mid(tmpGUID,  1, 2) ' 3
        octetStr = octetStr + Mid(tmpGUID, 11, 2) ' 4
        octetStr = octetStr + Mid(tmpGUID,  9, 2) ' 5
        octetStr = octetStr + Mid(tmpGUID, 15, 2) ' 6
        octetStr = octetStr + Mid(tmpGUID, 13, 2) ' 7
        octetStr = octetStr + Mid(tmpGUID, 17, Len(tmpGUID))
    
        ConvertGUIDtoOCTET = octetStr
    End Function
    
    					
  2. Run the script.

APPLIES TO
  • Microsoft Windows 2000 Standard Edition
  • Microsoft Active Directory Service Interfaces 2.5
  • Microsoft Active Directory Service Interfaces 2.5
Keywords: 
kbhowtomaster kbdswadsi2003swept KB325648