Regrettably, the .NET APIs as of this writing (preview version of .NET 8) also have this limitation - see:
Still, using the registry APIs directly offers a workaround.
(After a direct registry update, a WM_SETTINGCHANGE broadcast message must be posted to notify (at least) the Windows shell of the update).
Having proper support for REG_EXPAND_SZ env. vars. is important, especially given that neither the .NET APIs nor setx.exe (properly) provide it.
Regrettably, the .NET APIs as of this writing (preview version of .NET 8) also have this limitation - see:
Still, using the registry APIs directly offers a workaround.
(After a direct registry update, a
WM_SETTINGCHANGEbroadcast message must be posted to notify (at least) the Windows shell of the update).Having proper support for
REG_EXPAND_SZenv. vars. is important, especially given that neither the .NET APIs norsetx.exe(properly) provide it.