Today I needed to get the path of a substituted virtual drive through C# code. A substituted device can be made by using the subst command from the console. See subst form more info. Typing subst in the console with no parameters gives you a list of substituted drives with their physical path. It’s this path I wanted and I wanted it with as little effort as possible.
A quick search through the .Net Framework learnt me that there is no easy way to retreive the so much wanted path. So I turned to Google and searched for a while when I found A Delphi implementation of an “API for work with substitution device”. I noticed the use of the kernel32 function QueryDosDevice. This could be just the thing I needed.
I did a litle test with .Net Platform Invoke (PInvoke) and there it was, the path I was looking for. If you want to know how to import the QueryDosDevice function from the kernel32 library all you have to to is to find it on www.pinvoke.net or click here.