知識庫(3)-從Active Directory獲取物件的GUID (轉)

amyz發表於2007-11-25
知識庫(3)-從Active Directory獲取物件的GUID (轉)[@more@]

下面講述如何轉換一個十六進位制字元形式的的GUID到它的字串形式::namespace prefix = o ns = "urn:schemas--com::office" />

1.  將下列程式碼貼上到.VBS

'================================================================
'Set the next line to reflect a DN for an in the directory
'================================================================
Set obj = GetObject("://CN=Username,CN=Users,DC=AIN,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 flip 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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章