DriveInfo.GetDrives () does not return mapped drives at startup as administrator

I am creating a WPF application that, among other things, should check for multiple mapped drives. The code is simple:

DriveInfo[] systemDrives = DriveInfo.GetDrives(); foreach (DriveInfo i in systemDrives) { if ((i.Name.Contains("V")) && (i.IsReady)) { result = true; break; } } 

The mapped drives displayed are displayed to all users. The above code works fine when run as a normal user, however Visual Studio 2010 runs as an administrator, the GetDrives method returns only fixed disks and a DVD drive, but not mapped drives. The same thing happens if the executable is run as administrator. Any ideas why this might happen?

+4
source share
1 answer

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/ ):

This is normal behavior. As you saw on XP, drive mappings are user context specific. Therefore, if User1 has drive H: mapped to \ server \ share1, User2 does not automatically access this H: drive mapping; it exists only in the User1 session. If User2 wants access \ server \ share1, they need to create their own mapping, either H: drive or any other drive that fits.

Well, it looks like Vista ... just moreso.

Unlike previous versions of Windows, when an administrator logs on to a computer running Windows Vista, the administrator’s full access to the user is divided into two access tokens: administrator’s full access token and the user's standard access token. During the login process, authorization and access control, which identify the administrator is deleted, as a result, a standard user access token appears. The user's standard access token is used to start the desktop, Explorer.exe. Since all applications inherit their access to manage data from the initial launch of the desktop, they all run as a standard user. After entering the administrator’s system, the administrator’s access token is not called until the user tries to perform an administrative task.

So, when the administrator "rises" to perform some action that requires administrative access, their "divided token" is replaced, temporarily, with a full administrative token. Essentially, that means they now have a different user context. Thus, the display of drives is changed, too. Thus, drive H: no longer has a valid mapping to the current context.

The workaround I used was to open the admin command command - where you have the elevated token all the time - and create the appropriate drive mapping from there (network use h: \ server \ share1). since the standard user and the elevated administrator have a common understanding of what “H:” means, it means that everything is working fine.

I understand (well, it seems!) Why this design is in place. I will not try to criticize or defend him. But, there you have it.

In an ideal world, administrators could set up “global” mappings that automatically apply to each user context on the machine (almost like on real devices). But that did not happen. Most operating systems have useless trade-offs, to varying degrees.

+5
source

All Articles