Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This question already has an answer here:

How to get windows environment variabe in the C# code.

  1. I have a windows startup script to set the environment variables.
  2. I need to pass this variable to C# code..something like %var%

e.g. in the C# file, replace D:\ with %var%. The value of var is stored as an environment variable in windows.

Thanks

share|improve this question

marked as duplicate by Renan, Petesh, Paolo Tedesco, Alex K., LittleBobbyTables Jun 13 '13 at 14:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4  
msdn.microsoft.com/en-us/library/… –  Alex K. Jun 13 '13 at 14:35
1  
See: stackoverflow.com/questions/185208/… –  Jack Hughes Jun 13 '13 at 14:36
    
Indeed. Voting to close as duplicate. –  Renan Jun 13 '13 at 14:37
    
It's a duplicate, but why the downvotes without a comment for the OP? –  Paolo Tedesco Jun 13 '13 at 14:38
    
Aah, 3 down votes. LOL. Sorry, I am a Linux person, never worked on C#. Niether on Windows, so it could be a silly question for those who knows windows and C#. I have a small requirement to do this job. –  Shweta Chandrakar Jun 13 '13 at 14:44

2 Answers 2

Use the System.Environment class.

The method:

System.Environment.GetEnvironmentVariable()

and

System.Environment.SetEnvironmentVariable()

share|improve this answer
myvalue =  System.Environment.GetEnvironmentVariable(nameofthedesiredVar);

This is the command.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.