tags:

views:

114

answers:

2

Hi, im traversing through the registry, taking the values of the keys and storing them as strings. I have discovered there are many different types. Some of these types are causing my filestream writer to fail. Is it possible to convert all of the below into a string form. The actual data value is not important, just the ability to differentiate between different values.

  • DWORD
  • ExpandString
  • Binary (is this just the same as byte[] ?)
  • MultiString

-

if (String.Compare(SubKey.GetValueKind(v[i]).ToString(), "String") == 0)
{
    String s = SubKey.GetValue(v[i]).ToString();

    RegistryKeyDataValue rkdv = new RegistryKeyDataValue(s); 
    rkdv.incrementNumberOfTimesUsed();
    rkdv.setTypeOfData("S");

    r.addDataValue(rkdv);
    r.setCurrentDataValue(s);

    String hash = "";
    h.setHashData(hash); 

    hash = h.HashString(s);
}

I'm having problems later on because i want to write the values to a file and i need to convert all different types to a string.

A: 

You should take a look into the Registry.GetValue() description. Within the example all of these types are converted into a string.

Oliver
That is what im using, but later on when i extract the contents (which i got from the key using getValue()) im getting errors about weird characters being outputted.One error i had was something to do with unicode character 'u\144' or something?
Tom
@Tom: It's a good idea to include such information in the question so that people know what problem you actually need to have solved.
Fredrik Mörk
Ah sorry, i thought that problem was due to the one i stated in my question, ie unreadable data.
Tom
+1  A: 

There already is a decent standard for writing registry values as strings to a file. In Regedit.exe, use File + Export after selecting a key to see what that looks like. Documentation is available in this KB article.

Hans Passant
i used that several years ago to write a importer, exporter for WindowsCE 3.0
Oliver