大网数据广告活动
启动与系统组件

Convert string formatted GUID to hexadecimal string form

· 52CE 我爱测

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.

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.

Original KB number:   325648

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.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
- Supported versions of Windows Server · Source date 02/12/2026
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。