Link to home
Start Free TrialLog in
Avatar of sstew
sstew

asked on

Setting Environment variables from VB5

I want to set an NT environment variable from VB5. I can amend the registry entries at either HKEY_CURRENT_USER\Environment\ (User Variables) or HKEY_CURRENT_USER\Volatile Environment (general variables).

However, an NT command prompt or a COMMAND prompt does not notice the addition or change to these variables.

The only way I've found of getting NT to recognise the new variable or value is to open Control Panel, choose the System option and press OK.

Surely there must be an Api call to reread the registry settings?

I've search MSDN and Microsoft Knowledge Base to no avail.

Please help.
ASKER CERTIFIED SOLUTION
Avatar of waty
waty
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sstew
sstew

ASKER

The code which is in this KB article requires a pointer to a string containing the description of the registry settings which have changed, ie the  (LPARAM) "Environment" path of the call. The LPARAM function is not valid in VB5 - How can I get a pointer to a string for this function to work correctly?
Did you tried the following declaration
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, lpdwResult As Long) As Long

I should probably work as the SendMessage API :
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Avatar of sstew

ASKER

That declaration worked to a certain degree - I was using the one from the API viewer.

With a Windows NT command prompt open, I run my program which set the environment variable. However, when I do a SET command in the command prompt, the old value is shown. Only when I close the command prompt and reopen it is the new value available. This also happens with a NT DOS command prompt.

Any ideas why the change isn't being passed through?

By the way, you've earned your points. I'll give them to you on your next comment.
I think, when you open a command dos, it reads all the environment (like if you start your computer in dos, it reads the environment in the config.sys).

If you have to keep your dos box, you could maybe send through the clipboard commands ?