夥計們,查詢win32_NetworkConnection是
多年來慢在Windows 7上,我一直愉快地使用下面的C#IsNetworkDrive方法來確定「這是一個網絡驅動器?」在Windows XP下。它仍然在Windows 7下產生預期的結果,但每次調用需要10秒的時間...... ergo大概有一百萬次太長!
using System;
using System.Collections.Generic;
using System.Management;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (var driveName in Environment.GetLogicalDrives())
Console.WriteLine(driveName + " " + IsNetworkDrive(driveName.Substring(0,2)));
Console.Write("Press any key to continue ...");
Console.ReadKey();
}
private static bool IsNetworkDrive(string drive)
{
var query = @"SELECT Name FROM win32_NetworkConnection WHERE LocalName='" + drive + "'";
var seacher = new ManagementObjectSearcher(query);
var resultset = seacher.Get();
var count = resultset.Count;
return count == 1;
}
}
}
Arrrgggghhhh。我討厭Windows!
請問任何人有任何想法如何[執行]確定一個給定的驅動器號代表本地驅動器或網絡驅動器,在Windows 7和Windows XP(企業SOE的)?
[.NET中最好使用.NET < = 3.5,儘管我可以將項目升級到4.0,但它只需要一個綠地測試,我們現在沒有錢。感嘆。]
乾杯。基思。