Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Hex using VBscript

Status
Not open for further replies.

Robbman2000

Technical User
Jun 11, 2003
18
US
I need an example of how to read and write hex values in AD using VBScript. I think this has to be loaded into an array but I can't find a good example in all my books.

In ADSIEdit the value is listed as "OctetString" and looks like this:

0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x08 0x00 0x00 0x00 0x00 0x00 0x00

In LDP it is listed as "ldp: binary blob"
 
Here's an example that should get you started. I'm assuming the string is a single line, no vbCrLfs in it.

If you run this as is, do it in a command prompt window with CScript and capture the results to a file, since it echoes each value.

cscript ConvertHex.vbs > ConvertHex.out

- Todd

---
Code:
'- ConvertHex.vbs
'- run with CScript to avoid a million MsgBoxes

Option Explicit

say ""
say "converting C hex strings to values"
say "----------------------------------"

dim s ' holds the octet string
dim a ' holds the string split into individual elements
dim i
dim h ' value of each hex string

s = [OctetString from above]

s = Replace( s, "0x", "&H" ) ' convert C hex strings to VB
a = Split( s, " " )          ' split string on spaces

i = 0
do while i <= UBound( a )
  s = a( i )    ' s now contains &quot;&H08&quot;
  h = CInt( s ) ' CInt converts correctly formatted strings

  say s & &quot; -> &quot; & h
  i = i + 1
loop

say &quot;&quot;
say &quot;converting integer to hex string in C format&quot;
i = 255
s = Hex( i )  ' s = FF
s = &quot;0x&quot; & s  ' s = 0xFF, C format hex string

say i & &quot; -> &quot; & s

sub Say( s )
  WScript.Echo s
end sub
===
 
xift,

This code is awesome. It'll solve half my problem. I guess I need to elaborate on what I need specifically.

In Active Directory, using ADSIEdit, I can look at values of certain attributes in Active Directory for each object. I can use object.Get(&quot;valuename&quot;) or object.GetEx(&quot;multivalue&quot;). Can know how to work with Strings and Integers in AD. What I'm trying to figure out is how to do is get a value type of OctetString.

The following is what I expected to be able to use however GetEx does not recognize the OctetString type.

Set objServer = GetObject _
(&quot;LDAP://CN=MyServer,CN=Servers,CN=Admin Group,CN=Administrative Groups,CN=PHIBRED,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=MyDomain,DC=com&quot;)


For Each Octet in objServer.GetEx(&quot;msExchMailboxManagerActivationSchedule&quot;)

Wscript.Echo Octet

Next
 
I don't really know anything about ADSI or Active Directory, but a search on &quot;adsi octet&quot; on Google and Google Groups turned up some pages that might be useful for you. Best of luck!

-xift
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top