Re: How to create a "Array of Bytes" in VBScript?



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
> >
>
>


.



Relevant Pages

  • Re: Need a little help
    ... for the information to add to the arrays. ... JTextPane textPane = new JTextPane; ... String newArtist = JOptionPane.showInputDialog(null, "Please enter ... }//end public void actionPerformed ...
    (comp.lang.java.programmer)
  • Need a little help
    ... for the information to add to the arrays. ... JTextPane textPane = new JTextPane; ... String newArtist = JOptionPane.showInputDialog(null, "Please enter ... }//end public void actionPerformed ...
    (comp.lang.java.programmer)
  • Re: Can someone spot the error here?
    ... C, for example, has no strings, only character arrays. ... My programs generally do a lot of string handling, ... the compiler is strict) or an array of "MinChar .. ...
    (comp.lang.pascal.misc)
  • Re: pass complex structure to native function
    ... I have converted the code to VB.NET I've found that that crash was on String ... Public Class Struct1 ... Public numExtData As Integer ' Number of extended data structures ... >> Arrays, and also Arrays of another structures that also contains Strings, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: How to create a "Array of Bytes" in VBScript?
    ... you can do anything binary with Textstream. ... Since VBS uses Chrto demarcate string ends, ... any PE file that contains icons. ... ADODB if the target computer doesn't have the version ...
    (microsoft.public.scripting.vbscript)