I'm trying to figure out how much disk space is on a network drive. I have found several examples but none of them give me the correct size.
I used the info obtained from this question:
The code gives me disk space info, but what I don't understand is the number don't match up at all. The code says I had two drives a (C: and D:) which is correct, but then the code outputed that C: was 125GB and had 35GB free, the D: drive supposely was 23Gb drive with 11Gbs free. None of this info is even closely correct. C drive is a 20Gb drive with 13GB free and D drive is 450GB with 48GB free.
I also tried this on several other network drives and my local drive...and I got the SAME INDENTICAL NUMBERS as stated a above.
Can some one shed some light on this subject. What am I not seeing or not doing correctly????
ConnectionOptions oConn = new ConnectionOptions();
long gb = 134217728; //gigabyte
ntScope oMs = new System.Management.Manageme
//get Fixed disk stats
ery oQuery = new System.Management.ObjectQu
t FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(o
//Get the results
oReturnCollection = oSearcher.Get();
//loop through found drives and write out info
foreach( ManagementObject oReturn in oReturnCollection )
// Disk name
lw.WriteLine("Name : " + oReturn["Name"].ToString()
// Free Space in bytes
long ndiv = Convert.ToInt64(oReturn["F
lw.WriteLine("FreeSpace : " + ndiv.ToString());
// Size in bytes
ndiv = Convert.ToInt64(oReturn["S
lw.WriteLine("Size : " + ndiv);
Name : C:
FreeSpace : 35 GB
Size : 125 GB
Name : D:
FreeSpace : 11 GB
Size : 23 GB