CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    Saint Paul, Minnesota, US
    Posts
    91

    Change environment variable in console process ...

    Hi ...

    I have read many articles that describe the process to update environment variables in another process. As I understand I should be able to change the either of the regsitry values below ...

    HKEY_CURRENT_USER\Environment
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment";

    and then call SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0) tp propagate these setting to other applications.

    When I do this I do not see the environment variables in my current console process change when I use SET to display the environment variables in the console.

    ?? Why don't I see the change in the console ??

    Below is some code / Details:

    - I open a command prompt using Windows XP.

    - Use SET to view environment variables (MXBUILD_VERSION) is not present.

    - Start a command file that gets files from SourceSafe and then calls a program called ManageVersion.

    - ManageVersion will update the version info in the version.h file and then save the version info to an enviroment variable called MXBUILD_VERSION. I have sent this in both the User and System Regsitry in an attempt to propogate the value to the console enviroment. After the registry is update dhten I call the SendMessage() method.


    Code:
        // We tryed both methods
        nReturn = SendMessageTimeout(HWND_BROADCAST, 
                                     WM_SETTINGCHANGE, 
                                     0,
                                     (LPARAM) "Environment", 
                                     SMTO_ABORTIFHUNG,
                                     5000, 
                                     &dwReturnValue);
    
        nReturn = SendMessage(HWND_BROADCAST, 
                              WM_SETTINGCHANGE, 
                              0, 
                              0);
    Thanks,
    Chris
    [email protected]
    www.macgowan.com









    nReturn = SendMessage(HWND_BROADCAST,
    WM_SETTINGCHANGE,
    0,
    0);

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: Change environment variable in console process ...

    My understanding is that a process gets the environment variable set when it is launched. There is no auto refresh after that. Any new console processes will get the new env set

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured