Creating System Environment Variables
By Sergey - Posted on January 1st, 2008
MSDN:
| This is sample code. Add error handling and adjust to your requirements as necessary. |
#DEFINE HWND_BROADCAST 0xFFFF #DEFINE WM_SETTINGCHANGE 0x001A DECLARE INTEGER SendMessageTimeout IN WIN32API ; Long hWnd, Long Msg, Long wParam, String lParam, ; Long fuFlags, Long uTimeout, Long lpdwResult DECLARE Long GetLastError IN kernel32 && To programmatically add or modify system environment variables, add them && to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key. && WSH is used as an example. The registry key can be added by any other means available. oShell = Createobject("wscript.shell") lcEnvRegKey = "HKLM\System\CurrentControlSet\Control\Session Manager\Environment\" && Environment variable name lcEnvVarName = "Foo" && Environment variable value lcEnvVarVal = "FooValue" oShell.RegWrite(lcEnvRegKey + lcEnvVarName, lcEnvVarVal, "REG_SZ") && Broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment" && This allows applications, such as the shell, to pick up updates lnRetVal = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, "Environment", 0, 1000, 0) IF lnRetVal = 0 && Error ? GetLastError() ENDIF
Recent comments
1 hour 25 min ago
4 days 9 hours ago
4 days 10 hours ago
1 week 9 hours ago
1 week 11 hours ago
2 weeks 1 day ago
2 weeks 1 day ago
2 weeks 4 days ago
2 weeks 4 days ago
2 weeks 6 days ago