473,385 Members | 1,821 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,385 software developers and data experts.

Environment Values

My task is to read the environment variables and their values and show them in a listBox. I don't have any problems with getting the variables, but I'm not able to get their values...

Expand|Select|Wrap|Line Numbers
  1. switch (comboBoxRegion.Text)
  2. {
  3.     case "Global":
  4.         aktenv = new GlobalEnv();
  5.         aktGlobal = true;
  6.         break;
  7.     case "User":
  8.         aktenv = new UserEnv();
  9.         aktGlobal = false;
  10.         break;
  11.     FillComboBox();
  12. }
  13.  
  14. private void FillComboBox()
  15. {
  16.     if (aktGlobal)
  17.     {
  18.         foreach (string var in aktenv.EnumGlobalVars())
  19.         {
  20.             listBox1.Items.Add(var);
  21.         }
  22.     }
  23.  
  24.     else
  25.     {
  26.         foreach (string var in aktenv.EnumUserVars())
  27.         {
  28.             listBox1.Items.Add(var);
  29.         }
  30.     }
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
Dec 2 '11 #1
1 1483
Fr33dan
57
I cannot find any reference to the GlobalEnv or UserEnv objects you construct in your switch online and cannot compile your code.

You should be able to use System.Environment.GetEnvironmentVariables() to get a dictionary of environment variables, then just iterate through the the values collection instead (Also it's bad code to have the loop twice so I reworked it to only have one loop with different parameters if depending on what's needed):

Expand|Select|Wrap|Line Numbers
  1. System.Collections.ICollection vars;
  2. if (aktGlobal)
  3. {
  4.     vars = System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.Machine).Values;
  5.  
  6. }
  7. else
  8. {
  9.     vars = System.Environment.GetEnvironmentVariables(EnvironmentVariableTarget.User).Values;
  10. }   
  11. foreach (string var in vars)
  12. {
  13.     listBox1.Items.Add(var);
  14. }
Dec 5 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Artco News | last post by:
How to get Windows XP Server(where PHP Server is running) environment variables? I use the echo $_ENV seem to not working. The same for any other environment variables. I'm running PHP-4.3.4...
8
by: sebastien.hugues | last post by:
Hi I would like to retrieve the application data directory path of the logged user on windows XP. To achieve this goal i use the environment variable APPDATA. The logged user has this name:...
1
by: Shai Zohar | last post by:
We have encountered the following problem with DOT.NET 2003 development environment. Sometimes while debugging, we the environment does not display the values of DateTime variables and fields. ...
2
by: ruca | last post by:
Hi, Can anyone tell me please how can I return values from a popup to a UserControl. I use the same "method" like to return to a WebForm, but it not works in UserControl case. I have this...
0
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
3
by: Tristan | last post by:
Hello community: I post this because I could not find satisfactory answers in the posts generated by this nice group. I work on winXP. I have many little python applications in different folders,...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
3
by: Ronald S. Cook | last post by:
I have a string (see below) that I want to parse out the values. As you can see, some are element-based and some are attribute-based. <METADATA version="Format5"><TITLE value="Adrenaline...
2
by: Gerard Flanagan | last post by:
Hello, I have a third party shell script which updates multiple environment values, and I want to investigate (and ultimately capture to python) the environment state after the script has run....
5
by: Rider | last post by:
Hi All, Here is the reason why i ak asking for ur help. I have a edit form in which the values already stored in DB are populated. User can edit some or all the values in the form. then he...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.