Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a multiline REG_SZ string to the registry from the command line?

As part of a build setup on a windows machine I need to add a registry entry and I'd like to do it from a simple batch file.

The entry is for a third party app so the format is fixed.

The entry takes the form of a REG_SZ string but needs to contain newlines ie. 0xOA characters as separators.

I've hit a few problems.

First attempt used regedit to load a generated .reg file. This failed as it did not seem to like either either long strings or strings with newlines. I discovered that export works fine import fails. I was able to test export as the third party app adds similar entries directly through the win32 api.

Second attempt used the command REG ADD but I can't find anyway to add the newline characters everything I try just ends up with a literal string being added.

like image 312
morechilli Avatar asked Sep 30 '08 16:09

morechilli


1 Answers

If you're not constrained to a scripting language, you can do it in C# with

Registry.CurrentUser.OpenSubKey(@"software\classes\something", true).SetValue("some key", "sometext\nothertext", RegistryValueKind.String);
like image 166
Factor Mystic Avatar answered Sep 29 '22 18:09

Factor Mystic