RegSetExpSz

Sets a REG_EXPAND_SZ value in the registry.

Syntax:

RegSetExpSz(handle, subkey-string, value [,view-flag])

Parameters:

(i) handle an open registration database key (see below).

(s) subkey-string a path from the key provided to the desired key, including the "data item name" in square brackets
at the end of the key string.

(i) value data to be stored in the database at desired key.

(i) view-flag [optional] controls which registry view the function uses when accessing the Windows registry.
0 - view indicated by the last call to the RegOpenFlags.
32 - use the 32-bit registry view.
64 - use the 64-bit registry view.

Returns:

(i) @TRUE Data item value was stored.

 

View-flag

This optional parameter controls which registry view the function uses when accessing the Windows registry. The optional parameter's values can be 32 to use the 32-bit view, 64 to use the 64-bit view, or 0 to use the view indicated by the last call to the RegOpenFlags. The parameter value of 0 can also causes a function to use the WinBatch default 64-bit view, if no call to RegOpenFlags has been made and setting the parameter to 0 is equivalent to omitting the parameter entirely.

Notes:

Windows Vista/2008 and newer: This function may require an Administrator level account, if it attempts to access protected registry keys: HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT.

 

Example:


; Note: To modify path in NT 4.0+
; See the RegApp function
; The Following is the location of users path in Windows NT
; For the User Environment Path variable use:
userenv="Environment[path]"
; For the System Environment Path variable use:
sysenv="SYSTEM\CurrentControlSet\Control\Session Manager\Environment[path]"
; Directory to add to the path
addpath="Q:\"
If WinMetrics(-4)==4 ;Check to make sure system is Windows NT.
   LastError( ) ;clear the errors
   ErrorMode(@OFF) ;tell WB we'll handle the errors
   oldpath=RegQueryExpSz(@REGCURRENT, userenv)
   ErrorMode(@CANCEL)
   If LastError( ) == 1233
      Message("Users Path", "No path found, replacement not made.")
   Else
      newpath=StrCat(oldpath,";",addpath)
      c=RegSetExpSz(@REGCURRENT, userenv, newpath)
      Message("Users new path is", newpath)
      WININICHG=26
      DaDll=StrCat(DirWindows(1),"USER32.DLL")
      DllCall(DaDll,long:"SendMessageA",long:-1,long:WININICHG,long:0,lpstr:"Environment")
   EndIf
   Exit
Else
   Message("RegQueryExpSz","Not supported by Non-NT registry")
EndIf
See Also:

RegApp, RegEntryType, RegSetBin, RegSetDword, RegSetEx, RegSetMulSz, RegSetValue and the section on Registration Database Operations