How can I resolve a path with drive letter from a device path?
For example, convert
\Device\HarddiskVolume4\Windows\System32\RuntimeBroker.exe
into
C:\Windows\System32\RuntimeBroker.exe
Assuming HarddiskVolume4 maps to C: on this computer.
I have found this question, but I want to use it in C#.
Since we want a path with a drive letter we need to replace
\Device\HarddiskVolume4with the correct drive letter, e.g.C:. For that useQueryDosDeviceand map a dos device to each drive letter. Then we can search and replace for the dos device path.This is a possible implementation. It uses extension methods internal: