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

.net, c#, vb.net

Solution

`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.

Problem

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?

Original source