environment variables 
Author Message
 environment variables

Hi,

according to
http://www.*-*-*.com/ ://support.microso...
80/support/kb/articles/q104/0/11.asp&NoWebContent=1
the follwing code should be able to make what is passed to the function,
appear as an environment variable.

Now, it does appear in the registry at the correct place, but it does not
appear as an environment variable. So the SendMessageTimeout seems to fail,
but it does not return 0, which indicates that it should have suceeded. When
i log off and on, they do appear as environment variables. Anyone have any
idea?

ps: i know i'm using WM_WININICHANGE, but it's value is the same as
WM_SETTINGCHANGE, so that shouldn't be a problem.

Public Declare Function SendMessageTimeout Lib "user32" Alias
"SendMessageTimeoutA" _
(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam
As String, ByVal fuFlags As Long, ByVal uTimeout As Long, ByVal lpdwResult
As Long) As Long

Public Declare Function SetEnvironmentVariable Lib "kernel32" Alias
"SetEnvironmentVariableA" _
(ByVal lpName As String, ByVal lpValue As String) As Long

Public Const REG_SZ = 1
Public Const REG_EXPAND_SZ = 2
Public Const HWND_BROADCAST = &HFFFF&
Public Const WM_WININICHANGE = &H1A
Public Const HKEY_CURRENT_USER = &H80000001
Public Const SHREGSET_FORCE_HKCU = &H1
Public Const SMTO_ABORTIFHUNG = &H2

Sub SetEnvironmentVar(ByVal EnvName As String, ByVal EnvValue As String)
    Dim resApi As Long
    ' Set Environment Variable for the current process
    SetEnvironmentVariable(EnvName, EnvValue)
    WriteRegistry(Registry.CurrentUser, "Environment", "azerty", "zzz")
    Dim x As Long
    x = SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0,
"Environment", SMTO_ABORTIFHUNG, 5000, resApi)
End Sub

regards,
Kristof



Tue, 11 Oct 2005 22:48:00 GMT  
 environment variables
Hello,


Quote:
> Public Declare Function SendMessageTimeout Lib "user32" Alias
> "SendMessageTimeoutA" _
> (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam
> As String, ByVal fuFlags As Long, ByVal uTimeout As Long, ByVal lpdwResult
> As Long) As Long

VB6: Integer = 16-bit, Long = 32-bit
VB .NET: Integer = 32-bit, Long = 64-bit

Replace all longs with Int32s (As Int32 or As Integer). The hwnd parameter
can be declared as IntPtr.

Quote:
> Public Const HWND_BROADCAST = &HFFFF&

Remove the "&" character at the end of the value and declare the constants
as Int32 too.

Regards,
Herfried K. Wagner



Wed, 12 Oct 2005 00:29:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Environment variable...

2. Write Environment Variables

3. Environment Variables

4. Environment Variables

5. querying environment variables from vba

6. WORD Environment Variables

7. Using Environment Variable in Template path

8. Extracting environment variables

9. how to set an environment variable?

10. Environment Variables

11. Creating and environment variable and using it in the same cmd window

12. Getting Environment Variables

 

 
Powered by phpBB® Forum Software