Solved

I change Environment but VB doesnt see change?

Posted on 2000-02-23
6
193 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 27

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

786 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