I need to create a directory with the letter P (or whatever) so that it is like drive C or D.
After trying different methods, I came to the conclusion that it is best to do this with the help of Subst.
But how to do it in C#. The code I’m using doesn’t work. As administrator, does not work either.
`
string diskLetter = "P:"; // <---
string path = @"D:\folder path";
Process.Start(new ProcessStartInfo
{
FileName = "subst",
Arguments = $"{diskLetter} \"{path}\"",
Verb = "runas",
UseShellExecute = true
});
`
>Solution :
To use the subst command in C#, you can use the Process class to start a new process and run the command. Here is an example of how you can do this:
using System.Diagnostics;
// ...
string driveLetter = "P";
string path = "C:\\my\\folder\\path";
Process process = new Process();
process.StartInfo.FileName = "subst";
process.StartInfo.Arguments = $"{driveLetter}: {path}";
process.Start();
This will create a virtual drive with the letter P that maps to the folder at the specified path.
Note that you will need to have administrative privileges to create a virtual drive using subst. If the code is not working, it could be because the process is not being started with the necessary privileges. To start the process with administrative privileges, you can set the Verb property of the StartInfo object to "runas":
process.StartInfo.Verb = "runas";