0

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?

Ashish Sinha
  • 87
  • 2
  • 10

1 Answers1

0

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?

BitLauncher
  • 587
  • 4
  • 15
  • I think, all your points mentioned were to solve the problem of opening the custom created folder. Here I want to clarify that the Diagnostics.Process doesn't evaluate the variable and opens the custom folder only. My concern was for the Windows Run Command as it doesn't work that way. Run, as I have seen so far, always evaluate the variable whenever it finds a string enclosed with '%', and ignores the possibility that it could be name of a folder and hence the problem arises that how would my program differentiate between an actual folder and a variable? – Ashish Sinha Jun 07 '20 at 08:31