R
René Sørensen
How do i get the free diskspace from a windows logic drive like C:\
and a network path like \\file-server??
Rene
and a network path like \\file-server??
Rene
using System.Collections;
using System.Management;
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT *
From Win32_LogicalDisk ");
ManagementObjectCollection queryCollection = query.Get();
//loop throught each object to get drive information
foreach ( ManagementObject mo in queryCollection)
switch (int.Parse( mo["DriveType"].ToString()))
case 2: //removable drivesbreak;
case 3: //Local drives
case 4: //Network drives
Console.WriteLine("Drive: {0}, FreeSpace: {1}", mo["Name"],mo["FreeSpace"]);break;
case 5: //CD rom drivesbreak;
case 6: //Ram Diskbreak;
default: //defalut to folderbreak;
}
SerhaD said:Q: How to get the disk size and the free disk space?
A:
using System;
using System.Management;
Richard Grimes said:Yuck!
This is the way that Microsoft recommends, but it really is horrible. The
reason is that it means that you'll have an interprocess call to the WMI
service, using COM interop. That's a lot of CPU cycles. It's far quicker
to use platform invoke and call GetDiskFreeSpaceEx.
Richard
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.