Search code examples
windowscommand-linevbscriptregistry

writing multiple values to Reg_SZ


I have a application that needs multiple configuration files to be written to reg_sz as

"sEndorsement"="C:\\x\\file1.txt
C:\\x\\file2.txt"

Adding this via regedit doesn't works. i tried using a vbscript to do so as below,

Dim myval
myval = "C:\\x\\file1.txt" & VbCrLf _
& "C:\\x\\file2.txt" & VbCrLf _
& "C:\\y\\file3.dll" & VbCrLf

Dim WSHShell
set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_USERS\abc\def\TheSelectedFiles", myval, "REG_SZ"

But it still ended up in coming as single line.. i am not sure.. Is there someone can help me with it?? Thanks


Solution

  • For multiple lines, that's called REG_MULTI_SZ not REG_SZ. You cannot create keys under the root of HKEY_USERS, you need to use the .Default subkey. The values will appear to be on the same line, but if you double click the value, you can see there are 3 lines.

    Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\.\root\default:StdRegProv")
    Const HKEY_CLASSES_ROOT =    &H80000000
    Const HKEY_CURRENT_USER =    &H80000001
    Const HKEY_LOCAL_MACHINE =   &H80000002
    Const HKEY_USERS =           &H80000003
    Const HKEY_CURRENT_CONFIG =  &H80000005
    
    strKeyPath = ".DEFAULT\abc\def\TheSelectedFiles"
    MultValueName = "sEndorsement"
    iValues = Array("C:\x\file1.txt", "C:\x\file2.txt", "C:\y\file3.dll")
    objRegistry.CreateKey HKEY_USERS,strKeyPath
    objRegistry.SetMultiStringValue HKEY_USERS,strKeyPath,MultValueName,iValues