How to open a folder exactly named as an environment variable name, through Run Command?

187 Views Asked by At

Since I am working on a C# .NET application in which a portion imitates Windows Run command, I am doing some experiments with it. I have a folder exactly named as %userdomain% in ....Appdata\Local\Temp folder and I want to access through Windows Run command, but it gives me error as Windows cannot find ....Local\Temp\ComputerName. Is there any way I could access this folder through Run?

However in C# .NET, using System.Diagnostics.Process, I am able to open the folder concerned, but as '%' is a valid character for folder and file names, it is hard to determine that the path given by user contains a variable name or a folder name. And so it would not be wise to retrieve the value from Environment.GetEnvironmentVariable(""); all of the time. What would be the best way to differentiate?

Any suggestion?

1

There are 1 best solutions below

1
BitLauncher On

My ideas to solve it - they have to be proven to work - I am currently on a Linux machine:

  1. I do not know how to escape % in Windows area, that would the finest solution, anybody else?
  2. in C# temporarily backup the value of the environmentvariable %userdomain%, set the environment variable for this process to "%userdomain%" if it would work. And after calling Run command, reset userdomain environment variable to its backed up value (only disadvantage if some other thread uses %userdomain% at the same time in your program).
  3. Define and set 2 environment variables in C% like fakeLeftHalf = "%user" and fakeRightHalf = "domain%" and call Run command with "yourpath\%fakeLeftHalf%%fakeRightHalf%"

Did one idea work?