Reputation: 14915
I have an application that I use frequently on multiple machines. I would like to export the registry settings that I normally have to configure on each machine so I can script them to be imported at startup. The application allows me to put multiple lines of text into a text box, which will overlay that text on all printouts. It saves that text in a string in the registry. When I export the registry, the string looks something like this:
"sEndorsement"="Line 1 of text
Line 2 of Text"
This doesn't import properly because of the break in the string. Any ideas how to make that import nicely? I don't really have the option to just use one line of text in the settings.
Upvotes: 2
Views: 4161
Reputation: 302
As others have mentioned, you can use VBScript by using vbCrLf
with the RegWrite function.
Alternatively, and I'm not sure if this is possible within the context of your problem, change the registry key type to REG_MULTI_SZ
instead of REG_SZ
.
REG_MULTI_SZ
strings are null-terminated as such:
String 1\0String2\0String3\0
And you can walk through them after reading the registry and just join them with newlines in your app.
MSDN has a good description of how these work and a code sample.
Upvotes: 0
Reputation: 502
You can do one Python Script, using _winreg module. Some snippets:
from _winreg import *
#read Data:
key = OpenKey(HKEY_LOCAL_MACHINE, r'Software\MyCompany\MyApp', 0, KEY_ALL_ACCESS)
value_data = QueryValueEx(key, "MyValueName")[0]
#write data:
key = OpenKey(HKEY_LOCAL_MACHINE, r'Software\MyCompany\MyApp', 0, KEY_WRITE)
SetValueEx(key, "MyValueName", 0, REG_SZ, "MyValueData")
Upvotes: 0
Reputation: 5703
If the first line (or only line) of the key=value always starts with a double-quote, then your import code could detect that. Pseudo-code:
firstLine = TRUE
keyAndValue = NULL
for each line to import
line = get line
if line[0] == '"' then
if have previous line
import keyAndValue
keyAndValue = line
else
keyAndValue = concat(keyAndValue, CRLF, line)
end for
if keyAndValue is not NULL
import keyAndValue
As said before, this could be implemented in VBScript -- or Perl for that matter.
Upvotes: 0
Reputation: 4598
another approach assuming the app and its code is yours is to use a .ini file or other text file to save and load the settings from a standard place like %user-folder%\your-app-name\settings.txt
Upvotes: 0
Reputation: 4249
Instead of using the standard .reg file you got from exporting the settings, you'll have to do it via VBScript, using vbCrLf
to introduce the newlines in your string.
set ShellObj = CreateObject("WScript.Shell")
ShellObj.RegWrite "HKCU\Software\Key\sEndorsement", "Line1" & vbCrLf & "Line2", "REG_SZ"
Upvotes: 5