Solved

I change Environment but VB doesnt see change?

Posted on 2000-02-23
6
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month6 days, 5 hours left to enroll

627 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