ITPub博客

首页 > IT职业 > IT生活 > 知识库(3)-从Active Directory获取对象的GUID (转)

知识库(3)-从Active Directory获取对象的GUID (转)

原创 IT生活 作者:amyz 时间:2007-11-25 09:40:24 0 删除 编辑
知识库(3)-从Active Directory获取对象的GUID (转)[@more@]

下面讲述如何转换一个十六进制字符形式的对象的GUID到它的字符串形式:XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />

1.  将下列代码粘贴到.VBS文件

'================================================================
'Set the next line to reflect a DN for an object in the directory
'================================================================
Set obj = GetObject("LDAP://CN=Username,CN=Users,DC=domAIN,DC=COM")
MsgBox "The GUID string Value for user " & obj.Get("DisplayName") & _
  " is " &  ConvertHexStringGUIDToStringGUID(obj.GUID)

'================================================================
' 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) & "}"

  ConvertOctettoGUID = tmpGUID
End Function


2.运行脚本


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752019/viewspace-984542/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3984
  • 访问量
    7363274