473,847 Members | 2,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to 'set' an environment variable?

All:

I've found the 'Environment.Ge tEnvironmentVar iable()' method; but how do I
create and/or set an environment variable?

Thanks,
Bill
Nov 15 '05 #1
4 4216
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACH INE\SYSTEM\Cont rolSet001\Contr ol\Session Manager\Environ ment

User variables are stored in the following key:

HKEY_CURRENT_US ER\Environment

Maybe we can use the Microsoft.Win32 .Registry and the RegistryKey classes
to manipulate them directly.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2
Thanks,

Perhaps I'll just call the SetEnvironmentV ariable() Win32 API via P/Invoke.
I just figured the Framework Class Libraries wrapped this call, but I just
couldn't find it.

Thanks for your help,
Bill
"Felix Wang" <v-*****@online.mi crosoft.com> wrote in message
news:UV******** ******@cpmsftng xa07.phx.gbl...
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACH INE\SYSTEM\Cont rolSet001\Contr ol\Session Manager\Environ ment
User variables are stored in the following key:

HKEY_CURRENT_US ER\Environment

Maybe we can use the Microsoft.Win32 .Registry and the RegistryKey classes
to manipulate them directly.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
The reason why you're probably never gonna see SetEnvironmentV ariable in te
framework is due to the encouragement of utilizing config files as your
settings. Of course, we as developers can fight that by adding things back
in, but the focus has shifted from Environement Variables -> Registry ->
config files, and I think its a good change... its a whole lot easier to
shift config files around then it is to write a batch file or a "Reg Import"
when you want to duplicate or just move apps around.

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

"Bill Davidson" <bi***********@ getronics.com> wrote in message
news:uZ******** ******@TK2MSFTN GP10.phx.gbl...
Thanks,

Perhaps I'll just call the SetEnvironmentV ariable() Win32 API via P/Invoke. I just figured the Framework Class Libraries wrapped this call, but I just
couldn't find it.

Thanks for your help,
Bill
"Felix Wang" <v-*****@online.mi crosoft.com> wrote in message
news:UV******** ******@cpmsftng xa07.phx.gbl...
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACH INE\SYSTEM\Cont rolSet001\Contr ol\Session

Manager\Environ ment

User variables are stored in the following key:

HKEY_CURRENT_US ER\Environment

Maybe we can use the Microsoft.Win32 .Registry and the RegistryKey classes to manipulate them directly.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 15 '05 #4
Eric:
The reason why you're probably never gonna see SetEnvironmentV ariable in te framework is due to the encouragement of utilizing config files as your
settings
I figured this might be the case, but the Framework provides the
EnvironmentPerm ission class with the EnvironmentPerm issionAccess enumeration
that contains the 'Write' Permission defined as follows: "Write access to
environment variables is specified. Write access includes creating and
deleting environment variables as well as changing existing values. Reading
environment variables is not included in this access level".

'Seems like the .Net security model is all set up for handling environment
variables, but the methods for actually writing/creating these variables are
nowhere to be found.

Anyway, I found a workaround so I'll close this thread. Thanks to everyone
for their assistance.

Bill

"Eric Newton" <er**@cc.enso ft-software.com> wrote in message
news:#e******** ******@TK2MSFTN GP09.phx.gbl... The reason why you're probably never gonna see SetEnvironmentV ariable in te framework is due to the encouragement of utilizing config files as your
settings. Of course, we as developers can fight that by adding things back in, but the focus has shifted from Environement Variables -> Registry ->
config files, and I think its a good change... its a whole lot easier to
shift config files around then it is to write a batch file or a "Reg Import" when you want to duplicate or just move apps around.

--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

"Bill Davidson" <bi***********@ getronics.com> wrote in message
news:uZ******** ******@TK2MSFTN GP10.phx.gbl...
Thanks,

Perhaps I'll just call the SetEnvironmentV ariable() Win32 API via

P/Invoke.
I just figured the Framework Class Libraries wrapped this call, but I just
couldn't find it.

Thanks for your help,
Bill
"Felix Wang" <v-*****@online.mi crosoft.com> wrote in message
news:UV******** ******@cpmsftng xa07.phx.gbl...
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACH INE\SYSTEM\Cont rolSet001\Contr ol\Session

Manager\Environ ment

User variables are stored in the following key:

HKEY_CURRENT_US ER\Environment

Maybe we can use the Microsoft.Win32 .Registry and the RegistryKey

classes to manipulate them directly.

I hope this makes sense to you.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
26083
by: Eric Wichterich | last post by:
Hello Pythonistas, I am trying to get certain (self-written) libraries imported into my scripts using statements like "from library import function.py". But they are not being found. I think that the pythonpath-variable must be expanded to the location
1
3846
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System Properties"->Advanced->"Environment Variables". However, if I open a console and type 'set', "SSID" is not listed; also if I open a python shell and do os.environ the variable is not found. What am I doing wrong??? import _winreg
2
4595
by: Charles K. Clarkson | last post by:
I am trying to adapt an SSI content management system from an Apache server to an IIS 6 server and I am running into trouble because 'set' is not supported in IIS SSI. This is a typical file for a page (/bbs/index.shtml): <!--#set var="content_file" value="/bbs/messages.shtml" --> <!--#set var="title" value="Open Real Estate Investor Forum" --> <!--#set var="keywords" value="Real Estate Investment Club, blah blah
28
21012
by: Christian | last post by:
Another question from a not even newbie: In Unix you can set an environment variable with the command export PYTHONPATH but I would like to set the variable from at .py script. So my question is: How do I export an environment variable in a .py script?
0
947
by: bsfl44 | last post by:
As the .NET administrator, how (where) do you set the 'environment variables’? We are converting old COBOL applications to .NET. For the COBOL, we have an environment variable set to allow us to use: "folder\file", instead of the usual: "D:\folder\file". When the COBOL applications run on our clustered servers (2 IIS servers, 2 SQL 2000 servers, and SAN drives for data), our output data files arrive on the SAN just fine (we can see...
4
6437
by: Shiraz | last post by:
Hi I'm using Visual Studio Installer to make my installer, and have not as yet figured out a straightforward way to use it to set environmental variables. Amongst the various things I tried, I'm thinking the following might help. I would appreciate if someone could comment on this idea and possibly suggest a better one: The environement variable in question is 'Path' in the HKCU registry folder's Environment key. I want to add some...
2
5036
by: Ran Raj | last post by:
In Windows environment, I want to create/update both system and user environment variables. By default, I can access/modify the variables using Start > Control panel > System > Advanced > Envrionment variables. After log-off and log-in, I can see the changes. But I am trying to setup a job in scheduler to do specific task. It requires me to check/update few environment variable during the processing time.
1
3803
by: kraj123 | last post by:
Hi, How to Find ,if already a environment variable is set in hash table in perl. Actually i want to check if a environmental variable in perl script, which is present in oracle database has been already set its path in hash table in perl. that is i have to query the database server and check whether it has been set as environment variable or not. so basically i want to check with if statment to sdatabase erver name and a loop to...
4
16604
by: vkbishnoi | last post by:
I need to create an environment variable for another local user in windows. For example, say suppose there are 2 users in the system (User1 and User2). Currently User1 is logged in the system. Now Is there any way we can create user level environment variable for User2 using C# .Net 2.0. If we use Environment.SetEnvironmentVariable(envName, envValue, EnvironmentVariableTarget.User) then it will create the environment variable for the...
0
9727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10978
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10643
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9477
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7879
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4113
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3158
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.