michals
Nov 19th, 2000, 05:26 PM
Does anyone know how to set environment variables without logging off in WinNT?
So far, I consulted the MSDN and came up with the following which does seem to work after I log off from my workstation.
Public Function CreateEnvSetting(name As String,
value As String)
Dim messageText As String
Dim result As Long
Dim rc As Long
messageText = "Environment"
If Registry.UpdateKey(HKEY_CURRENT_USER,
messageText,
name,
value) Then
rc = SendMessageTimeout(HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
StrPtr(messageText),
SMTO_ABORTIFHUNG,
1000,
result)
End If
End Function
The idea being that you change the registry where the environment variables are held, then you broadcast a message to all toplevel windows that an environment setting has changed. This is where the problem lies. Although the SendMessageTimeout function returns success, nothing seems to happen and all windows (I tried a command prompt) remain in their previous state, even if restarted.
Does anyone have any ideas?
So far, I consulted the MSDN and came up with the following which does seem to work after I log off from my workstation.
Public Function CreateEnvSetting(name As String,
value As String)
Dim messageText As String
Dim result As Long
Dim rc As Long
messageText = "Environment"
If Registry.UpdateKey(HKEY_CURRENT_USER,
messageText,
name,
value) Then
rc = SendMessageTimeout(HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
StrPtr(messageText),
SMTO_ABORTIFHUNG,
1000,
result)
End If
End Function
The idea being that you change the registry where the environment variables are held, then you broadcast a message to all toplevel windows that an environment setting has changed. This is where the problem lies. Although the SendMessageTimeout function returns success, nothing seems to happen and all windows (I tried a command prompt) remain in their previous state, even if restarted.
Does anyone have any ideas?