|
-
February 16th, 2005, 12:38 PM
#1
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
-
February 17th, 2005, 05:07 PM
#2
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...
-
February 17th, 2005, 05:14 PM
#3
Re: environment variable problem
This was in the MSDN article you reference, my bold added:
 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.
-
February 18th, 2005, 03:05 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|