Note that there are some explanatory texts on larger screens.

plurals
  1. POC# RegistryKey.GetValue doesn't return blank lines
    primarykey
    data
    text
    <p>So I'm writing some code and using <code>RegistryKey.GetValue</code> and I can't seem to get it to return the proper string array. I would use RegSaveKeyEx except I need to change the location of where the keys are being saved to in the reg file I'm creating.</p> <p>The MultiString I'm querying has two lines in it, <code>:</code> and a blank line. Regedit gives <code>hex(7):3a,00,00,00,00,00</code> for the reg file export of said value. This is correct. 3a would be <code>:</code>, then a null, two nulls for the blank line and finally two more nulls to signify the end of the value. My code is giving <code>hex(7):3a,00,00,00</code>, which would be a <code>:</code> and the double-null EOL characters on a MultiString. When imported back into the registry <code>hex(7):3a,00,00,00</code> is only a <code>:</code>, the blank line is missing.</p> <p>If I import <code>hex(7):3a,00,00,00,00,00</code> then view the value in regedit, I see <code>:</code> and a blank line. This is correct and this is what I want my code to do.</p> <p>When I query this value with <code>RegistryKey.GetValue</code> in C# 4.0 I get the a <code>string[]</code> with just one element, the <code>:</code>.</p> <p>For other MultiString values I get an array containing an element for every line, as I would expect.</p> <p><code>RegistryKey.GetValue</code> doesn't return anything for the blank line. It doesn't return a null, a blank string in the array, nothing.</p> <p>On everything except blank lines it returns exactly the same result as regedit export. What needs to be changed to have it return an array that includes the blank line?</p> <p>Here's my code if that's helpful:</p> <pre><code>private static string RegMultiStringExtraction(RegistryKey UsersSubKey, string Key) { string[] InputStrs = (string[])UsersSubKey.GetValue(Key, Environment.NewLine, RegistryValueOptions.DoNotExpandEnvironmentNames); StringBuilder sb = new StringBuilder(); foreach (string str in InputStrs) { char[] Values = str.ToCharArray(); foreach (char letter in Values) { int ValueInt = Convert.ToInt32(letter); sb.Append(ValueInt.ToString("x")); sb.Append(",00,"); if (Values.Length == 0) { if (sb.Length == 0) { sb.Append("00,"); } else if (sb.Length &gt; 1) { sb.Append(",00,"); } } } sb.Append("00,00,"); } string Value = ('"' + Key.ToString() + @"""=" + "hex(7):" + sb.ToString().TrimEnd(',')); return Value; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload