Re: How to create a "Array of Bytes" in VBScript?
- From: "Richard Mueller [MVP]" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 May 2005 11:14:00 -0500
Hi,
The problem is that some Active Directory attributes, like logonHours, are
byte arrays. AD will not allow you to assign a variant array or binary
string to logonHours. Byte arrays can be read and handled in VBScript (with
effort), but you cannot declare or create a variable of datatype byte().
Fortunately, VBScript can read byte arrays from AD or the ADODB.Stream
object. ADO allows you to write bytes to the stream and ADO does the
conversion.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--
"mayayana" <mayaXXyana1a@xxxxxxxxxxxxxxxx> wrote in message
news:HP%ke.7597$M36.4958@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> You didn't mention what you need this for, but
> you can do anything binary with Textstream. You
> don't need ADODB and in many cases you
> don't need conversion to bytes. A Textstream string
> is binary until you look at it (quantum Textstream?).
> Since VBS uses Chr(0) to demarcate string ends,
> if you try to get the length of the string you'll get
> the offset of the first Chr(0). If you try to use ReadAll
> you'll only read up to the first Chr(0). Aside from those
> limitations, you can read and write binary as Textstrream
> strings.
>
> If you use:
>
> A1 = Array(1, 0, 100, 200, 255, 10)
>
> you'll get a variant array. But those values can
> be written to a string:
>
> For i = 0 to UBound(A1)
> s = s & Chr(A1(i))
> Next
>
> ....and the string can be written to disk as binary.
>
> For an example that reads and writes binary, also
> using arrays to set up binary data, see here:
>
> http://www.jsware.net/jsware/jsware/scripts.html#iconextr
>
> It's a script that uses only Textstream to read from
> any PE file that contains icons. It parses the resource
> table, extracts the icon bytes, writes binary file headers
> for each icon by using the array method above, then writes the
> icons to disk. It may seem a bit sloppy to use Textstream for
> that but it works, and on my Win98 1660 Athlon it extracts
> and writes 350-odd icons from Shell32.dll almost instantly.
> (It also avoids the version limitation associated with using
> ADODB if the target computer doesn't have the version
> with the Stream object - 2.6+, I think.)
>
> --
> --
> Arno Bosch <ArnoBosch@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:797EE731-4F86-4882-A272-A907174625FF@xxxxxxxxxxxxxxxx
> > Hi Richard,
> >
> > I tried Michaels example code and had good results for chr(i) where
> > 0<=i<=127 but it did not work for 128<=i<=255 at all.
> >
> > You have to change the line "Stream.Charset = "ASCII"" to
"Stream.Charset
> =
> > "windows-1252"" for making it work for 0<=i<=255.
> >
> > So this code should work for my problem even though it is a detour when
I
> > first have to create a file and then can import it as a byte-array.
> >
> > Anyway I get the correct data-type (8209=array of byte). Thats what I
> wanted!
> >
> > Thanks a lot to both of you for your help!
> >
> > Arno
> >
>
>
.
- References:
- How to create a "Array of Bytes" in VBScript?
- From: Arno Bosch
- Re: How to create a "Array of Bytes" in VBScript?
- From: Richard Mueller [MVP]
- Re: How to create a "Array of Bytes" in VBScript?
- From: Michael Harris \(MVP\)
- Re: How to create a "Array of Bytes" in VBScript?
- From: Richard Mueller [MVP]
- Re: How to create a "Array of Bytes" in VBScript?
- From: Arno Bosch
- Re: How to create a "Array of Bytes" in VBScript?
- From: mayayana
- How to create a "Array of Bytes" in VBScript?
- Prev by Date: sql query error
- Next by Date: Re: Allow user to run application as a power user
- Previous by thread: Re: How to create a "Array of Bytes" in VBScript?
- Next by thread: Re: "Reverse Order"
- Index(es):
Relevant Pages
|