Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expand environment variable %CommonProgramFiles%\system\ in .NET

Tags:

I have a situation where I need to return a directory path by reading the registry settings. Registry value returns me a path in the format

%CommonProgramFiles%\System\web32.dll 

while the consumer code is expecting it in the format

C:\Program Files\Common Files\System\web32.dll 

How can I resolve such directory path in .net code?

like image 554
Faisal Avatar asked Apr 25 '10 07:04

Faisal


People also ask

How do I get Environment Variables in .NET core?

Open project properties by right clicking on the project in the solution explorer and select Properties. This will open properties page. Click on Debug tab and you will see Environment Variables as shown below. You may change the value as per your need.

What is environment variable in C#?

The GetEnvironmentVariable(String) method retrieves an environment variable from the environment block of the current process only. It is equivalent to calling the GetEnvironmentVariable(String, EnvironmentVariableTarget) method with a target value of EnvironmentVariableTarget.


1 Answers

Environment.ExpandEnvironmentVariables. If you control the creation of the registry value, store it as an expandable string in the registry and the registry API will automatically expand it for you.

like image 184
Marcelo Cantos Avatar answered Sep 28 '22 17:09

Marcelo Cantos