开发者

C# Environment.GetDrives() not working correctly in administrator mode

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 .N开发者_如何学CET 4 framework.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜