I'm creating a WPF app that among other things should check for the existence of several mapped drives. The code is straightforward:
DriveInfo[] systemDrives = DriveInfo.GetDrives();
foreach (DriveInfo i in systemDrives)
{
if ((i.Name.Contains("V")) && (i.IsReady))
{
result = true;
break;
}
}
The mapped drives are mapped fro all users. The code above works fine when run as a regular user, however is Visual Studio 2010 is run as administrator the GetDrives method only returns the Fixed drives and the DVD drive but not the mapped drives. The same happens if the executable is run as an administrator. Any ideas why this might be happening?
You can enable that also mapped drives are visible to the administrator by a registry entry:
HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System
create DWORD EnableLinkedConnections with value 1
as described here: http://www.winability.com/how-to-make-elevated-programs-recognize-network-drives/
This worked for me on Win 10.
From http://www.vistaheads.com/forums/microsoft-public-windows-vista-general/125180-run-administrator-loses-access-mapped-drives.html,
(via http://social.technet.microsoft.com/Forums/en-US/w7itpronetworking/thread/31c9eff2-ece3-4430-886d-19b54796e411/):