How to detect freespace and disk information from one server to other in C#

前端 未结 2 1772
名媛妹妹
名媛妹妹 2021-01-06 21:12

If there are 3 pcs on network and if I want to detect the freespace and disk details of one pc from another pc then how to go about it... I have found this code. but I don

相关标签:
2条回答
  • 2021-01-06 21:18

    The code checks all the drives on the pc where you run this program. It returns a table with 2 entries per drive. One with the name and one with the free space. You can just write a simple program that uses this method and displays this data. It should be possible to query the drives from a remote computer. Maybe this article can tell you more http://msdn.microsoft.com/en-us/library/ms257337%28v=vs.80%29.aspx

    EDIT:

    public Hashtable ReadFreeSpaceOnNetworkDrives(String FullComputerName)
    {
         ManagementScope scope = new ManagementScope(fullComputerName);
         scope.Connect();
         //create Hashtable instance to hold our info
         Hashtable driveInfo = new Hashtable();
         //query the win32_logicaldisk for type 4 (Network drive)
         SelectQuery query = new SelectQuery("select name, FreeSpace from win32_logicaldisk where drivetype=4");
    
         //execute the query using WMI
         ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope,query);
         //loop through each drive found
         foreach (ManagementObject drive in searcher.Get())
         {
            //add the name & freespace to our hashtable
            driveInfo.Add("Drive", drive["name"]);
            driveInfo.Add("Space", drive["FreeSpace"]);
         }
         return driveInfo;
    }
    
    0 讨论(0)
  • 2021-01-06 21:38

    covert into c#. and that may help you. http://www.codeguru.com/forum/showthread.php?t=426869

    0 讨论(0)
提交回复
热议问题