Solved

I change Environment but VB doesnt see change?

Posted on 2000-02-23
6
204 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

839 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