On Mon, 02 Jun 2008 13:44:02 -0700, auldh
<au***@discussi ons.microsoft.c omwrote:
the output i can create for a "multi_sz" is something like this: [snip]
Now we're getting somewhere! That example was precisely the sort of
information needed to elaborate on your question.
[...]
creates the output to be strings as seen above.
and according to "regedit" it can not import the structure i have.
Yes, that's true. As the docs say, and as you're aware, there's a
specific format required and that format is different from the one you're
using.
You need to do a couple of things. Ironically, using the managed
RegistryKey class makes things harder in one respect: the data returned is
not actually exactly how the data appears in the registry, so you need to
convert _back_ to the correct format so that you can then write it to the
text file. Were you using the unmanaged API (e.g. RegQueryValueEx ), you'd
just get the appropriate bytes directly (assuming you defined "UNICODE",
which IMHO any modern application should :) ).
Anyway, so the first thing you need to do is generate the necessary byte
array. You can use the Unicode instance of the Encoding class to convert
each string to a string of bytes. The REG_MULTI_SZ format is, as you can
probably tell by looking at the example you posted, a single byte array
containing null-terminated Unicode strings, with one more null-terminator
after the last null-terminated string (basically, it ends in a zero-length
string :) ).
So, you need to enumerate all your strings, convert them to Unicode bytes,
and fill a single byte array with the result. There are lots of ways to
do this, but the simplest is probably just to create a MemoryStream, write
the individual string byte arrays you get (including null-termination) to
the MemoryStream, and then get the bytes out from the MemoryStream at the
end. Don't forget that last zero-length string at the end (the extra
null-terminator).
Once you have this array of bytes, you need to write to the text file,
using hexadecimal formatting. The "X" formatting code can be used for
this, along with normal text output (e.g. StreamWriter.Wr iteLine(), which
you already seem to be using). Make sure you specify a 2-character field
width for each byte, and of course separate them with commas, exactly as
in your example. I don't actually know if the line-continuations are
required or if you can simply emit one long line. But you might want to
include the line-continuations even if they're not mandatory, since it
makes the file easier to read (granted, not many people are going to be
reading the byte values directly, but still... :) ).
Hope that helps. :)
Pete