Solved

I change Environment but VB doesnt see change?

Posted on 2000-02-23
6
214 Views
Last Modified: 2010-05-02
using this command for instance
go to Dos and check SET USERNAME and it has perhaps
USERNAME=XYZ
from VB we type
?Environ$("UserName")
in immediate mode and get "XYZ" back
everything makes sense!

But now I go to a Command Prompt in NT
and I type SET USERNAME=ABC

and go back into VB and do
?Environ$("UserName") again it will still say the old name "XYZ" not "ABC" and even if I exit and reload VB it still says the original setting

How can I make VB see the new refreshed Environment string?
0
Comment
Question by:vbmeister
  • 4
6 Comments
 

Accepted Solution

by:
visualman3 earned 100 total points
ID: 2552063
Have you changed the environment variable in NT by doing the following:

Right click on My Computer
Click Properties
Click the Environment Tab
Type UserName in the "Variable" field
Type 'ABC' in the "Value" field
Click the 'SET' button
0
 

Author Comment

by:vbmeister
ID: 2552160
No but unless this is something which can be done in VB it is really not going to be useful.  

A dos command can be done from VB with Shell command or we can maybe use API calls if needed to heopfully solve this problem.  

I'm just hopeful someone has tried to get environments refreshed from VB like this and can help.

Thanks!
0
 

Author Comment

by:vbmeister
ID: 2552174
Whats even more amazing is YES I did what you suggest and it says ABC in both the My Computer environment AND in DOS when typing SET and STILL VB comes up with XYZ??

I finally had to run a reload ini files api command (such as in the recent change wallpaper discussion) to get it to see the setting saved in the My Computer environment.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:Ark
ID: 2552577
Hi
Win32's environment variables can be different for different processes. "Global" environment variables are setting when system loading. Then you can change them for current process, or need to restart toset new "global" values. You can change  this variables for your app:

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

SetEnvironmentVariable "USERNAME", "ABC"

But this change is only for your app process. BTW, you can not change environment for yor app like this
Shell "cmd /c set username=ABC", because it change variable for Dos process. IMHO, if you want to change environment for all processes, you have to add a string to autoexec.bat and restart computer.
May be there is another way, but I don't know.
0
 

Author Comment

by:vbmeister
ID: 2555267
All we need is to find the way to change the Windows My Computer environment as I just said using VB code and your answer may work I have not tried it yet.

As pointed aout above you can:

Right click on My Computer
Click Properties
Click the Environment Tab
Type UserName in the "Variable" field
Type 'ABC' in the "Value" field
Click the 'SET' button

This WILL in fact change the Windows known Environment variables as is needed.  I'm certain we can change the DOS environment and issue the restart WINDOWS command without doing a complete reboot and changing autoexec but this is a worst case.

Thanks for your efforts.  This is an interesting topic I feel because it is strange that the environment per each workspace is so parallel and yet separate.  It's almost buggy.
0
 

Author Comment

by:vbmeister
ID: 2591932
oh well apparently it cant be done
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question