CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002
    Posts
    82

    environment variable problem

    Hallo,

    I wrote a function to propagate the environment variable as recommended in the MSDN article Q104011

    It worked fine. I could later on see the variable on the shell using set.

    I wrote another function to get the environment variable. Curiously, I can get back the new propagated environment variable.

    Code:
    Dim strMyNewVar as String
    Dim strVariable as String
    Dim objWSH
    Set objWSH = CreateObject("WScript.Shell")
    
    
    strMyNewVar = “%MyNewVar%”
    
    strVariable = objWSH.ExpandEnvironmentStrings(strVariable)
        
    Debug.Print strVariable '(give nothing)
    
    Am I doing something wrong?
    james

  2. #2
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    651

    Re: environment variable problem

    I'm not familiar with this at all, but something I noticed was:

    Code:
    Dim strMyNewVar as String
    Dim strVariable as String
    Dim objWSH
    Set objWSH = CreateObject("WScript.Shell")
    
    
    strMyNewVar = “%MyNewVar%”
    
    strVariable = objWSH.ExpandEnvironmentStrings(strVariable) '<-- Should this be strMyNewVar ?
        
    Debug.Print strVariable '(give nothing)
    Since you just declared strVariable, it's passing an empty string to ExpandEnvironmentStrings.
    I'd rather be wakeboarding...

  3. #3
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    516

    Re: environment variable problem

    This was in the MSDN article you reference, my bold added:

    Quote Originally Posted by MSDN
    However, note that modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. The changes do not take effect until you log off and then log back on.

    To effect these changes without having to log off, broadcast a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications (such as Program Manager, Task Manager, Control Panel, and so forth) can perform an update.
    Last edited by Comintern; February 17th, 2005 at 05:15 PM. Reason: Quote got chopped.

  4. #4
    Join Date
    Nov 2002
    Posts
    82

    Re: environment variable problem

    Hallo Comintern,

    thanks a lot for responding.

    You forgot to read in detail my original post that rfefers to the MSDN article Q104011.


    Hi malleyo,

    you are wright with your notice. it was a type mistake. But that was not the probleme.

    The think was that I started vb before propagate the setting change.


    Thanks
    james

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