以管理员身份运行时,DriveInfo.GetDrives()不返回映射的驱动器 [英] DriveInfo.GetDrives() not returning mapped drives when run as administrator

查看:306
本文介绍了以管理员身份运行时,DriveInfo.GetDrives()不返回映射的驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建WPF应用,除其他事项外,该应用应检查是否存在多个映射驱动器。代码很简单:

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;
     }

 }

映射的驱动器是全部映射的用户。以常规用户身份运行时,上面的代码可以正常工作,但是以管理员身份运行Visual Studio 2010时,GetDrives方法仅返回固定驱动器和DVD驱动器,而不返回映射的驱动器。如果可执行文件以管理员身份运行,也会发生同样的情况。

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?

推荐答案

来自> http://www.vistaheads.com/forums/microsoft-public- windows-vista-general / 125180-run-administrator-loses-access-mapped-drives.html

(通过 http://social.technet.microsoft.com/论坛/ zh-CN / w7itpronetworking / thread / 31c9eff2-ece3-4430-886d-19b54796e411 / ):


这是实际上是正常的行为。如您在XP上所见,驱动器映射
特定于用户上下文。因此,如果User1具有驱动器H:映射到
服务器共享1,则User2不会自动获得对该
H:驱动器映射的任何访问权限;它仅存在于User1的会话中。如果User2要
访问服务器 share1,则需要创建自己的映射,即
H:驱动器或任何其他合适的驱动器。

This is actually normal behaviour. As you saw on XP, drive mappings are specific to a user context. So if User1 has a drive H: mapped to \server\share1, User2 does not automatically get any access to this H: drive mapping; it only exists in User1's session. If User2 wants to access \server\share1, they need to create their own mapping, either H: drive or any other drive which suits.

好吧,在Vista中也是如此....只是如此。

Well, it is kind of the same in Vista .... only moreso.

与以前版本的Windows不同,当管理员登录到$ b时在运行Windows Vista的$ ba计算机上,用户的完全管理员访问权
令牌被分为两个访问令牌:完全管理员访问权
令牌和标准用户访问令牌。在登录过程中,将删除标识
管理员的
授权和访问控制组件,从而生成标准的用户访问令牌。
然后使用标准用户访问令牌启动桌面,即
Explorer.exe进程。因为所有应用程序都从最初启动桌面时继承其访问
控制数据,所以它们也都以
标准用户身份运行。管理员登录后,在用户尝试
执行管理任务之前,不会调用完整的
管理员访问令牌。

Unlike previous versions of Windows, when an administrator logs on to a computer running Windows Vista, the user's full administrator access token is split into two access tokens: a full administrator access token and a standard user access token. During the logon process, authorization and access control components that identify an administrator are removed, resulting in a standard user access token. The standard user access token is then used to start the desktop, the Explorer.exe process. Because all applications inherit their access control data from the initial launch of the desktop, they all run as a standard user as well. After an administrator logs on, the full administrator access token is not invoked until the user attempts to perform an administrative task.

因此,当管理员提升执行某种需要管理访问权限的操作
,他们的拆分令牌被临时管理员
替换为一个完整的管理令牌。实际上,这意味着
现在具有不同的用户上下文。因此,驱动器映射也更改了
。因此,H:驱动器在当前上下文中的
中不再具有有效的映射。

So, when an administrator "elevates" to perform some kind of action which requires administrative access, their "split token" is replaced, temporarily, with a a full administrative token. In effect, this means they now have a different user context. So the drive mappings are changed, as well. So the H: drive, no longer has a valid mapping in the current context.

我使用的解决方法是打开管理命令提示符
-您一直都拥有一个提升的令牌-并从那里创建一个匹配的驱动器映射(网络使用h:\server\share1)。由于标准用户和高级管理员

具有 H:驱动器的含义有共同的理解,所以一切正常。

The workaround I have used is to open an administrative command prompt - where you have an elevated token all the time - and create a matching drive mapping from there (net use h: \server\share1). Since the standard user and the elevated administrator have a common understanding of what "H:" drive means, everything runs okay.

我了解(嗯,有点!)为什么要进行这种设计。我不会试图批评或捍卫它。但是,就在那里。

I understand (well, sort of!) why this design is in place. I won't attempt to criticize or defend it. But, there you have it.

在理想的情况下,管理员应该能够配置
全局映射,该映射自动应用于每个用户上下文
在机器上(几乎像真实设备一样)。但是,那没有发生。
大多数操作系统在不同程度的
上都有很多杂乱的折衷。

In an ideal world, administrators would have been able to configure "global" mappings, which automatically applied to every user context on the machine (almost like real devices). But, that didn't happen. Most operating systems have a mish-mash of untidy compromises, in varying degree.

这篇关于以管理员身份运行时,DriveInfo.GetDrives()不返回映射的驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆