C#检测网络驱动器的剩余磁盘空间

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

using System;
using System.Management;
  
class NetworkSpace
{
  static void Main(string[] args)
  {
    SelectQuery query = new SelectQuery(
        "select name, FreeSpace from win32_logicaldisk where drivetype=4");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
  
    foreach (ManagementObject mo in searcher.Get())
    {
      Console.WriteLine("Drive letter is: {0}", mo["name"]);
      Console.WriteLine("Drive's free space is: {0}", mo["FreeSpace"]);
    }
  
    // Here to stop app from closing
    Console.WriteLine("\nPress Return to exit.");
    Console.Read();
  }
}