473,473 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to 'set' an environment variable?

All:

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

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

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Se ssion Manager\Environment

User variables are stored in the following key:

HKEY_CURRENT_USER\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 SetEnvironmentVariable() 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.microsoft.com> wrote in message
news:UV**************@cpmsftngxa07.phx.gbl...
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Se ssion Manager\Environment
User variables are stored in the following key:

HKEY_CURRENT_USER\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 SetEnvironmentVariable 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**************@TK2MSFTNGP10.phx.gbl...
Thanks,

Perhaps I'll just call the SetEnvironmentVariable() 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.microsoft.com> wrote in message
news:UV**************@cpmsftngxa07.phx.gbl...
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Se ssion

Manager\Environment

User variables are stored in the following key:

HKEY_CURRENT_USER\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 SetEnvironmentVariable 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
EnvironmentPermission class with the EnvironmentPermissionAccess 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.ensoft-software.com> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl... The reason why you're probably never gonna see SetEnvironmentVariable 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**************@TK2MSFTNGP10.phx.gbl...
Thanks,

Perhaps I'll just call the SetEnvironmentVariable() 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.microsoft.com> wrote in message
news:UV**************@cpmsftngxa07.phx.gbl...
Hi Bill,

Thanks for posting.

System environment variables are stored in the following key:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Se ssion

Manager\Environment

User variables are stored in the following key:

HKEY_CURRENT_USER\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
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...
1
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...
2
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...
28
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...
0
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...
4
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...
2
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 >...
1
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...
4
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.