c# – DriveInfo.GetDrives()在以管理员身份运行时不返回映射驱动器
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – DriveInfo.GetDrives()在以管理员身份运行时不返回映射驱动器,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3034字,纯文字阅读大概需要5分钟。
内容图文
![c# – DriveInfo.GetDrives()在以管理员身份运行时不返回映射驱动器](/upload/InfoBanner/zyjiaocheng/799/d731d776f4304ef5a8ba8a2b6a47eb84.jpg)
我正在创建一个WPF应用程序,除其他外应检查是否存在多个映射驱动器.代码很简单:
DriveInfo[] systemDrives = DriveInfo.GetDrives();
foreach (DriveInfo i in systemDrives)
{
if ((i.Name.Contains("V")) && (i.IsReady))
{
result = true;
break;
}
}
映射的驱动器将映射到所有用户.上面的代码作为普通用户运行时工作正常,但是Visual Studio 2010以管理员身份运行,GetDrives方法仅返回固定驱动器和DVD驱动器,但不返回映射驱动器.如果可执行文件作为管理员运行,则会发生相同的情况任何想法为什么会这样?
解决方法:
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.Well, it is kind of the same in Vista …. only moreso.
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.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.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.
内容总结
以上是互联网集市为您收集整理的c# – DriveInfo.GetDrives()在以管理员身份运行时不返回映射驱动器全部内容,希望文章能够帮你解决c# – DriveInfo.GetDrives()在以管理员身份运行时不返回映射驱动器所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。