Solved

I change Environment but VB doesnt see change?

Posted on 2000-02-23
6
172 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now