473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem with GetEnvironmentVariable

the GetEnvironmentVariable method returns "Nothing" when used against a
environment variable, created by me.
I've tried using SET from the console, or "Environment Variables" in my
computer properties.
Tested on 2 PCs.

Whats the problem?

Nov 21 '05 #1
6 3796
Also I can read some of the current system variables like "windir".

The example in MSDN also don't show my variable, but I can sse it using
SET from the command prompt

Example source:
' Sample for the Environment.GetEnvironmentVariables method
Imports System
Imports System.Collections

Class Sample
Public Shared Sub Main()
Console.WriteLine()
Console.WriteLine("GetEnvironmentVariables: ")
Dim environmentVariables As IDictionary =
Environment.GetEnvironmentVariables()
Dim de As DictionaryEntry
For Each de In environmentVariables
Console.WriteLine(" {0} = {1}", de.Key, de.Value)
Next de
End Sub 'Main
End Class 'Sample

Nov 21 '05 #2
Try restarting the PC after you add your vars into the properties area. I
don't think those are dynamic. They get read in when you boot up and I don't
think they get refreshed without a restart...

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
the GetEnvironmentVariable method returns "Nothing" when used against a
environment variable, created by me.
I've tried using SET from the console, or "Environment Variables" in my
computer properties.
Tested on 2 PCs.

Whats the problem?

Nov 21 '05 #3
"Ray Cassick" <rc******@nospam.enterprocity.com> schrieb:
Try restarting the PC after you add your vars into the properties area. I
don't think those are dynamic. They get read in when you boot up and I
don't
think they get refreshed without a restart...


It's possible to define environment variables in a batch file which will be
valid until the batch file is processed. I often follow this approach to
start tools which need certain environment variables without the need of
changing the whole system's environment variables.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
I can see them, without doint restart using the SET command from the
console.
Also can assign new values, works just fine.
Except in my app.

Nov 21 '05 #5
Yes, but can you create them in one session (batch file) and see then in
another?

I just opened 2 command windows.. in one I typed 'set tester=me'. Ten in
that same window I typed set and was able to view it. In the second command
window I typed set it was not present. Seems to prove that env vars defined
in a batch files do not cross process boundaries.

Now, I created an env var named tester in my system properties (as a system
env var) and set its value. Once I hit apply I could open a command window
and type set and see it there..
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eM**************@TK2MSFTNGP12.phx.gbl...
"Ray Cassick" <rc******@nospam.enterprocity.com> schrieb:
Try restarting the PC after you add your vars into the properties area. I don't think those are dynamic. They get read in when you boot up and I
don't
think they get refreshed without a restart...
It's possible to define environment variables in a batch file which will

be valid until the batch file is processed. I often follow this approach to
start tools which need certain environment variables without the need of
changing the whole system's environment variables.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6
"Ray Cassick" <rc******@nospam.enterprocity.com> schrieb:
Yes, but can you create them in one session (batch file) and see then in
another?


No, but you should be able to see them in an application that is started
from within the batch file.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

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

Similar topics

1
by: DotNetJunkies User | last post by:
I developed a Windows Service that uses the Oracle Client software. When I dump the "path" statement in the Service program it is not the same as the System Administrative screen path. The Service...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Garfield | last post by:
We have written a small function to append a couple of paths to the path environmental variable. The code is: string PathValue = ""; string sAdd = ""; sAdd = ";" + <path1> + "Bin;" +...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
0
by: François Lemaire | last post by:
I had an ASPNET application keeping files into the LocalApplicationData folder of the ASPNET account in IIS 5.0 which worked perfectly, but it doesn't workon IIS 6.0 (windows server 2003). I rely...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
5
by: =?Utf-8?B?Z215ZXJz?= | last post by:
Hello, I am attempting to start a cmd.exe process and pass several .vbs scripts (with additional parameters) and then read the output from the scripts and make "notes" in a DataTable (the...
3
by: =?Utf-8?B?Sm9yZ2UgQWx2ZXM=?= | last post by:
Hi. I am trying to do a CGI in C#. I have found code and explanation in http://west-wind.com/weblog/posts/1143.aspx : using System; using System.IO; using System.Collections; using...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.