mrwhipple
asked on
disk space
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:
https://www.experts-exchange.com/questions/20747539/Free-Disk-space.html?query=check+disk+space+and+C&clearTAFilter=true&showAll=true
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????
Thanks!
CODE:
ConnectionOptions oConn = new ConnectionOptions();
long gb = 134217728; //gigabyte
System.Management.Manageme ntScope oMs = new System.Management.Manageme ntScope("\ \\\na0029" , oConn);
//get Fixed disk stats
System.Management.ObjectQu ery oQuery = new System.Management.ObjectQu ery("selec t FreeSpace,Size,Name from Win32_LogicalDisk where DriveType=3");
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(o Ms,oQuery) ;
//Get the results
ManagementObjectCollection 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 reeSpace"] )/gb;
lw.WriteLine("FreeSpace : " + ndiv.ToString());
// Size in bytes
ndiv = Convert.ToInt64(oReturn["S ize"])/gb;
lw.WriteLine("Size : " + ndiv);
}
OUTPUT:
Name : C:
FreeSpace : 35 GB
Size : 125 GB
Name : D:
FreeSpace : 11 GB
Size : 23 GB
I used the info obtained from this question:
https://www.experts-exchange.com/questions/20747539/Free-Disk-space.html?query=check+disk+space+and+C&clearTAFilter=true&showAll=true
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????
Thanks!
CODE:
ConnectionOptions oConn = new ConnectionOptions();
long gb = 134217728; //gigabyte
System.Management.Manageme
//get Fixed disk stats
System.Management.ObjectQu
//Execute the query
ManagementObjectSearcher oSearcher = new ManagementObjectSearcher(o
//Get the results
ManagementObjectCollection
//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);
}
OUTPUT:
Name : C:
FreeSpace : 35 GB
Size : 125 GB
Name : D:
FreeSpace : 11 GB
Size : 23 GB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
With my mapped drives, I can see them when I change the DriveType=4 (networked drives). I'm not sure how your system is set up. Do you have a mapped drive to the other computer, or is it just a folder? How is it set up?
ASKER
I have it setup as a mapped drive.
I get the info when I change my DriveType=4, excellent, is it possible to do it with out the drive being mapped? Reason I asked is because this code will be part of a program that is on 200+ processing machines that are able to access 30+ network storage machines. So it will be cumbersome if I have to map all the network storage machines on all 200+ machines!
Thanks.
I get the info when I change my DriveType=4, excellent, is it possible to do it with out the drive being mapped? Reason I asked is because this code will be part of a program that is on 200+ processing machines that are able to access 30+ network storage machines. So it will be cumbersome if I have to map all the network storage machines on all 200+ machines!
Thanks.
mrwhipple
Now you are asking a different question. I guess a way you could do it is to query the name of all computers on the network (or a list of them that you already know)--and then use the above code to retreive the local drive(s) on the system. If you happen to know the setup of each of the storage systems, it might be a bit easier.
Regards,
NTAC
Now you are asking a different question. I guess a way you could do it is to query the name of all computers on the network (or a list of them that you already know)--and then use the above code to retreive the local drive(s) on the system. If you happen to know the setup of each of the storage systems, it might be a bit easier.
Regards,
NTAC
ASKER
I get the right numbers when I test my local machine, but it seems when I try and access a network machine I get the same values. Does this code not work when accessing a machine that is not locally?
Does the path matter? the machine name is na0029, I get no errors when using it : (ie)
System.Management.Manageme
I've tried adding to the path: for example add the shared folder on to the path, but all that does is error out on the above line.
Thanks.