C# Environment.GetDrives() 在管理员模式下无法正常工作
当我仅在标准用户模式下运行此代码时,我会获取所有驱动器,包括网络驱动器。以管理员身份运行时,网络驱动器不会出现在列表中。什么给?
List<string> drives = Environment.GetLogicalDrives().ToList();
StringBuilder driveList = new StringBuilder();
foreach (string drive in drives)
driveList.AppendLine(drive);
MessageBox.Show(driveList.ToString());
它在 Windows 7 下运行。网络驱动器来自 Novell。该代码是使用 .NET 4 框架用 C# 编写的。
When I run this code in just standard user mode, I get all my drives including the network drives. When run as administrator, the network drives don't appear in the list. What gives?
List<string> drives = Environment.GetLogicalDrives().ToList();
StringBuilder driveList = new StringBuilder();
foreach (string drive in drives)
driveList.AppendLine(drive);
MessageBox.Show(driveList.ToString());
This is being run under Windows 7. The network drives are from Novell. The code is written in C# using the .NET 4 framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正常行为,因为 Windows Vista 网络映射驱动器不可用于以提升的权限运行的进程(请参阅在 Windows Vista 或 Windows 7 中打开用户帐户控制后,程序可能无法访问某些网络位置 (KB 937624))。知识库文章中的解决方法意味着注册表编辑和计算机重新启动。
另请参阅博客文章Windows Vista 上使用 UAC 映射网络驱动器 了解更多详细信息。
This is normal behaviour since Windows Vista network-mapped drives are not available to a process ran with elevated privileges (see Programs may be unable to access some network locations after you turn on User Account Control in Windows Vista or in Windows 7 (KB 937624)). The workaround in the knowledge base article implies registry editing and a computer restart.
See also the blog post Mapped Network Drives with UAC on Windows Vista for more details.