Search code examples
c#registry

How long can be the maximum size for RegistryValueKind.String?


I'm trying to write a string value that could be very long (about 100k)

string key = @"HKEY_CLASSES_ROOT\my-key-name";
string valueName = "my-value-name";
string value = "a-very-long-string ..."; // this could be about 100,000 chars

Microsoft.Win32.Registry.SetValue(key,valueName, value,
   Microsoft.Win32.RegistryValueKind.String);

I have not found any documentations on the value size by searching google and .. How can i make sure that this will work on most operating systems such as Windows XP, Windows 7, Windows Server 2003 and so on. any advice is appreciated.


Solution

  • From MSDN:

    • Key name: 255 characters.
    • Value name: 16,383 characters
    • Value: Available memory (latest format) / 1 MB (standard format)

    So as long as you keep it below 1 MB it seems you should be good. The page does seem kinda old though, so I would guess that the 1 MB limit is for Windows 9x and older. Just a guess though..!

    Edit: And yes, as Hans just commented. Bad idea, that's not what the registry is for...