Re: wmi or vbscript help
- From: "Paul Randall" <paulr901@xxxxxxxxxxxx>
- Date: Fri, 27 Jul 2007 12:30:38 -0600
"TDM" <rpuffd@xxxxxxxxx> wrote in message
news:%23uzh0C9zHHA.1100@xxxxxxxxxxxxxxxxxxxxxxx
"Paul Randall" <paulr901@xxxxxxxxxxxx> wrote in message
news:%23d$2CzlzHHA.5476@xxxxxxxxxxxxxxxxxxxxxxx
If the file is not too big (5 or 10 megabytes is probably not too big),
then the ADODB stream object can be used. There are a few non-obvious
things you have to do, outlined in VBScript I posted on
microsoft.public.scripting.vbscript newsgroup in February.
Groups.google for the string "how to update binary field types in ADO"
-Paul Randall
Paul,
File is a meager 2K in size. I had some spare time so I took a wack
at trying to edit this file and I achieved some level of success, but not
an acceptable level.
Perhaps you can shed some light on editing binary data in vbs ? I found
very little useful info from google. What I did was use ADO to inhale
the binary file(bootstat.dat), then converted the binary data to string
using a funcion from Michael Harris(byteArrayToHexString). Then
I changed the byte in question(10, base 0), and it was putting the data
back as binary that I was not able to achieve full success with.
My problem seems to be related to the fact that when I conver the string
back to binary, it is then writing back an extra byte(00) back to the
file.
If you can shed any light on how you might handle this, that would be
nice.
TIA
TDM
Perhaps it doesn't have to be this complicated.
The FSO object has a number properties or methods that produce stream
objects that are designed to read and write text files. The documentation
does not claim any binary capability. The text can be encoded in one of the
many 8-bit encodings or 16-bit Unicode. But you want to read and write
8-bit binary data.
You can use the Chr() function to create 8-bit characters and ChrW() to
create Unicode characters. Within VBScript strings, every character takes
up 16 bits of space, so you can mix Chr() and ChrW() in the same string.
Unicode files are not identified by some property in the directory; the
first two bytes of the file is the identification and is called the Byte
Order Mark, or BOM. FFFE indicates Unicode in the PC world. The
FSO automatically writes these two bytes to a file when Unicode is
specified, at the time the file is created, and they are not returned as
part of the file contents when it is read as Unicode.
The stream object's reading and writing methods typically have parameters to
specify whether 8-bit (improperly called ASCII) or Unicode text is being
used. If the script lies, and try to write a string containing a Unicode
character to a non-Unicode file, you will get an error. When you open a
file for reading, you can specify whether it is to be read in 8-bit mode,
Unicode mode, or let the system figure it out from BOM. If the script lies,
and tries to read a Unicode file in 8-bit mode, you DON'T get an error. You
can try to use the stream's readall method to return every byte of the
entire Unicode file; some number of bytes near the beginning of the
resulting string will be the actual value of the bytes in the file -- the
first two bytes will be Chr(255) and Chr(254) -- but eventually things go
wrong, with no error indicated, and the bytes of the string don't match the
corresponding byte in the file even through the length of the string will
match the file size (on small files, all bytes may match). On the other
hand, if the first two bytes of the file are not FFFE, then every byte in
the string matches every byte in the file. So, while undocumented, you can
read a binary file if it does not start with FFFE.
So how about just
1) readall the file in 8-bit mode, erroring out if the first two bytes are
FFFE.
2) create a new string as the concatenation of three things:
a) Left-part of file up to the byte that is to be changed
b) Chr(the new byte value)
c) Right-part of the file beyond the byte that is to be changed
3) Write this new string back to the original file, forcing overwrite.
Provide sample code and I will help you with it.
-Paul Randall
.
- References:
- Re: wmi or vbscript help
- From: TDM
- Re: wmi or vbscript help
- From: TDM
- Re: wmi or vbscript help
- From: Paul Randall
- Re: wmi or vbscript help
- From: TDM
- Re: wmi or vbscript help
- Prev by Date: some (c++) code for "a" script control
- Next by Date: Re: developing VB Scripts
- Previous by thread: Re: wmi or vbscript help
- Next by thread: Re: Inventory Script
- Index(es):
Relevant Pages
|