Re: Convert a String to GUID
- From: "Richard Mueller [MVP]" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 11 Jul 2005 11:03:39 -0500
Hi,
The value of objectGuid is set by the system and cannot be modified.
http://msdn.microsoft.com/library/en-us/adschema/adschema/a_objectguid.asp
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
<wiltbank@xxxxxxxxx> wrote in message
news:1121083867.028864.189430@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Richard,
>
> Someone found this article on Microsoft that converts a string to an
> OctetString GUID for querying AD...
> http://support.microsoft.com/default.aspx?scid=kb;en-us;325648
>
> My only issue now is trying to set the computer GUID at the time I'm
> trying to create the object... For example:
>
> Set oComputer = computerContainer.Create("computer", "CN=" &
> sComputerName)
> oComputer.Put "samAccountName", sComputerName + "$"
> oComputer.Put "userAccountControl", lFlag
> oComputer.Put = "objectGUID", ConvertStringGUIDToHexStringGUID(strGUID)
> oComputer.SetInfo
>
> Apparently, the objectGUID object doesn't support the Put method --
> even at the time of creation. Any suggestions?
>
> Rob
>
>
> Richard Mueller [MVP] wrote:
> > Rob wrote:
> >
> > > In the process of install automation, we're trying to convert the
> > > string representation of a GUID (EEF00083-3454-5c6c-9ACB-FC9E8394FC8D,
> > > for example) to that of the actual GUID datatype appropriate to be
> > > stored inside of Active Directory.
> > >
> > > Is there an easy to to accomplish this?
> >
> > Hi,
> >
> > GUID's are stored in OctetString syntax, which is a byte array. Byte
arrays
> > cannot be created or modified in VBScript. This could be done in VB,
where
> > you can declare a varible as a byte array, but it would be a lot of
work.
> > Your string would have to first be converted from what I call the
display
> > form, to a hex string form. Then the hex string would be converted to a
byte
> > array. You might be able to find API functions to assist you in VB.
> >
> > The opposite conversion is possible in VBScript. The byte array can be
> > converted to a hex string, then the hex string converted to the display
form
> > you used. Below is an example:
> >
> > Set objUser = GetObject("LDAP://cn=JSmith,ou=Sales,dc=MyDomain,dc=com")
> >
> > arrbytGuid = objUser.objectGuid
> > strHexGuid = OctetToHexStr(arrbytGuid)
> > Wscript.Echo "User Guid in hex string format: " & strHexGuid
> >
> > strGuid = HexGuidToGuidStr(strHexGuid)
> > Wscript.Echo "User Guid in display format: " & strGuid
> >
> > Function OctetToHexStr(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 HexGuidToGuidStr(strGuid)
> > ' Function to convert Hex Guid to display form.
> > Dim k
> >
> > HexGuidToGuidStr = ""
> > For k = 1 To 4
> > HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 9 - 2*k, 2)
> > Next
> > HexGuidToGuidStr = HexGuidToGuidStr & "-"
> > For k = 1 To 2
> > HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 13 - 2*k, 2)
> > Next
> > HexGuidToGuidStr = HexGuidToGuidStr & "-"
> > For k = 1 To 2
> > HexGuidToGuidStr = HexGuidToGuidStr & Mid(strGuid, 17 - 2*k, 2)
> > Next
> > HexGuidToGuidStr = HexGuidToGuidStr & "-" & Mid(strGuid, 17, 4)
> > HexGuidToGuidStr = HexGuidToGuidStr & "-" & Mid(strGuid, 21)
> > End Function
> >
> > --
> > Richard
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab web site - http://www.rlmueller.net
> > --
>
.
- References:
- Convert a String to GUID
- From: wiltbank
- Re: Convert a String to GUID
- From: Richard Mueller [MVP]
- Re: Convert a String to GUID
- From: wiltbank
- Convert a String to GUID
- Prev by Date: Re: Convert a String to GUID
- Next by Date: Re: Convert a String to GUID
- Previous by thread: Re: Convert a String to GUID
- Next by thread: Re: Convert a String to GUID
- Index(es):
Relevant Pages
|