views:

2045

answers:

2

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 charcters everything I try just ends up with a literal string being added.

Any ideas?

A: 

You could create a VBScript(.vbs) file and just call it from a batch file, assuming you're doing other things in the batch other than this registry change. In vbscript you would be looking at something like:
set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\SOMEKEY", "value", "type"

You should be able to find the possible type values using google.

tloach
morechilli
+1  A: 

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);
Factor Mystic
Thanks but I'm fine with doing this from a program or even other scripting languages I was just hoping to do it without adding any more dependencies or complication
morechilli