Modify a REG_EXPAND_SZ reg value

(imported topic written by SystemAdmin)

I’m looking to modify a registry value where the type is reg_expand_sz. I am working on creating a relevance to determine the exisiting value. This is what I have so far in my Q&A, it will report back as true for REG_SZ values, but false on the reg_expand_sz that I am trying to work with.

exists values “Driver” whose (it as string = “%25WINDIR%25\system32\sqlsrv32.dll%00”) of keys “HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\SQL Server” of registry

This should populate as true, but Q&A will only answer false.

(imported comment written by MattBoyd)

Is this on a 64-bit OS? Try using the native registry inspector:

exists values "Driver" whose (it as string = "%25WINDIR%25\system32\sqlsrv32.dll%00") of keys "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\SQL Server\" of native registry

I know I’m very late to this party, but since this post is the first result when searching “REG_EXPAND_SZ” I thought I’d post a solution here.

REG_EXPAND_SZ values are stored internally as two-byte hexadecimal representations of their strings. We can read the value as string in Relevance, but when setting the value in Action Script it needs to be hexadecimal encoded. An example from the Registry Editor Wizard gives

delete __createfile
delete wizardedit.reg

createfile until @end_create_reg_file
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"PATH"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,44,00,61,00,74,00,61,00,5c,00,4f,00,72,00,61,00,63,00,6c,00,65,00,5c,00,4a,00,61,00,76,00,61,00,5c,00,6a,00,61,00,76,00,61,00,70,00,61,00,74,00,68,00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,3b,00,25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,62,00,65,00,6d,00,3b,00,25,00,53,00,59,00,53,00,54,00,45,00,4d,00,52,00,4f,00,4f,00,54,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,50,00,6f,00,77,00,65,00,72,00,53,00,68,00,65,00,6c,00,6c,00,5c,00,76,00,31,00,2e,00,30,00,5c,00,3b,00,43,00,3a,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,5c,00,43,00,43,00,4d,00,3b,00,25,00,53,00,59,00,53,00,54,00,45,00,4d,00,52,00,4f,00,4f,00,54,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4f,00,70,00,65,00,6e,00,53,00,53,00,48,00,5c,00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,46,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,53,00,51,00,4c,00,20,00,53,00,65,00,72,00,76,00,65,00,72,00,5c,00,43,00,6c,00,69,00,65,00,6e,00,74,00,20,00,53,00,44,00,4b,00,5c,00,4f,00,44,00,42,00,43,00,5c,00,31,00,33,00,30,00,5c,00,54,00,6f,00,6f,00,6c,00,73,00,5c,00,42,00,69,00,6e,00,6e,00,5c,00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,46,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,53,00,51,00,4c,00,20,00,53,00,65,00,72,00,76,00,65,00,72,00,5c,00,31,00,34,00,30,00,5c,00,54,00,6f,00,6f,00,6c,00,73,00,5c,00,42,00,69,00,6e,00,6e,00,5c,00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,46,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,53,00,51,00,4c,00,20,00,53,00,65,00,72,00,76,00,65,00,72,00,5c,00,31,00,34,00,30,00,5c,00,44,00,54,00,53,00,5c,00,42,00,69,00,6e,00,6e,00,5c,00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,46,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,53,00,51,00,4c,00,20,00,53,00,65,00,72,00,76,00,65,00,72,00,5c,00,31,00,34,00,30,00,5c,00,54,00,6f,00,6f,00,6c,00,73,00,5c,00,42,00,69,00,6e,00,6e,00,5c,00,4d,00,61,00,6e,00,61,00,67,00,65,00,6d,00,65,00,6e,00,74,00,53,00,74,00,75,00,64,00,69,00,6f,00,5c,00,3b,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,46,00,69,00,6c,00,65,00,73,00,5c,00,50,00,75,00,54,00,54,00,59,00,5c,00,00,00
@end_create_reg_file

move __createfile wizardedit.reg
waithidden regedit /s "wizardedit.reg"

In my case, I wish to add “C:\Sysinternals” to the system-wide PATH variable. The difficulty then is in retrieving the existing value, appending “;C:\Sysinternals” to it, and encoding the result in a way that the registry editor can import it. I came up with the following:

if {value "Path" of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" of registry as string as lowercase does not contain (pathname of root folder of drive of system folder & "\SysInternals\") as lowercase}

delete __createfile
delete wizardedit.reg

createfile until @end_create_reg_file
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
"PATH"=hex(2):{concatenation "," of (it as hexadecimal; "00") of characters of (it & ";" & (pathname of root folder of drive of system folder & "\SysInternals\") & "%00") of (if it ends with "%00" then preceding text of last "%00" of it else it) of (value "Path" of keys "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" of registry as string)}
@end_create_reg_file

move __createfile wizardedit.reg
waithidden regedit /s "wizardedit.reg"
3 Likes