Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry strings vs CRLF vs Regedit

Status
Not open for further replies.

Sheri99

Technical User
Feb 29, 2004
48
US
I'm using a program that stores strings (REG_SZ type) in the registry. These strings can and often do contain carriage returns and linefeeds. When the strings are viewed in regedit, the CRLF characters look like box characters, but the rest of the string looks normal. If I export these strings with RegEdit, then delete the keys and reimport, the strings do not import correctly. How do you get CRLF's into REG_SZ values using a reg file? Somewhere I read you can do it by specifying as hex(1), but so far I have been unable to make a reg file, which when imported, creates or modifies strings containing CRLFs.

Sheri
 
Are you thinking of perhaps a REG_MULTI_SZ? REG_SZ is normally used when you want a single value in a string and REG_MULTI_SZ when you want multiple values in the the same key (like an array)

Here is a small excerpt on how to do it with WMI.
This assumes you already have a key called HKCU\TestKey
Const HKEY_CURRENT_USER = &H80000001
dim mwValue
strComputer = "."

Set objRegistry=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "testkey"

strValueName = "Enabled"


mwValue = array("This is", "a", "test")


objRegistry.SetMultiStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,mwValue

Notice that the "distinct values" you want to use are enclosed in quotes and seperated by commas.

Hope this helps.

Lt
 
Thanks for the replies. Nothing I found on the web solved the issue. Lt, the keys I wanted to batch update are REG_SZ. Sometimes the strings need to include CRLFs.

I had read that you could update strings in hex via a .reg file, and that use of hex(1) would result in REG_SZ. That also didn't work, at least initially.

The missing ingredient is that the string must be converted to unicode and then hex encoded. Likely not applicable to Win98-ME; not sure about Windows 2K. Necessary in Windows XP.

So that's how to get them in there. When exported from the registry, such strings are still truncated though.

Regards,
Sheri
 
This talks about using double slashes, and even double, double (4) slashes, and Tab Key and LF characters, might pay to have a look?

Reg File to Create System DSN
thread779-1128697
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top