RE: CD Rom used,free and capacity

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

v-jetan_at_online.microsoft.com
Date: 03/10/04


Date: Wed, 10 Mar 2004 08:19:05 GMT

Hi John,

Thank you for posting in the community!

Based on my understanding, you want to retrieve the CDRom's used,free and
capacity space.

========================
You may use WMI to get this done.

You can use Win32_LogicalDisk Wmi class. For this class, you can use Size
property to get the capacity of the disk, use the FreeSpace property to get
the freespace. Then, the used space can be calculate from Size- FreeSpace.

Do like this:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("select *
from Win32_LogicalDisk WHERE DriveType =4");
foreach(ManagementObject mo in searcher.Get())
{
        MessageBox.Show( "FreeSpace: "+mo["FreeSpace"].ToString());
        MessageBox.Show( "CapacitySpace: "+mo["Size"].ToString());
                uint64 usedspace= (uint64)mo["Size"]-
(uint64)mo["FreeSpace"];
        MessageBox.Show( "UsedSpace: "+ usedspace.ToString());
}

Also, you may COM interop the Scripting FileSystemObject to get this done:

Scripting.FileSystemObject FSO = new Scripting.FileSystemObjectClass();
string [] logDrives=System.IO.Directory.GetLogicalDrives();
for ( int i =0;i< logDrives.GetUpperBound(0)+1;i++)
{
        Scripting.Drive thisdrive=FSO.GetDrive(logDrives[i]);
        if (thisdrive.DriveType==Scripting.DriveTypeConst.CDRom )
        {
                MessageBox.Show(thisdrive.Path+" FreeSpace: "+thisdrive.FreeSpace );
                MessageBox.Show(thisdrive.Path+" TotalSize: "+thisdrive.TotalSize );
        }
}

================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Relevant Pages

  • Re: PolAdtEv
    ... I did try posting a question about this on ... entire array instead of just the first 254 characters? ... >This is more a WMI question and not SMS related. ... tried tojsut get the data from the registry into ...
    (microsoft.public.sms.inventory)
  • RE: Determine Handle Count associated with a running process.
    ... Thank you for posting in the community! ... Instrumentation (WMI) to implement the corresponding function. ... I have created a test project in VB codes on my site, ... This posting is provided "AS IS" with no warranties and confers no rights. ...
    (microsoft.public.vb.winapi)
  • Re: corrupt local area connection advanced properties
    ... This posting is provided "AS IS" with no warranties, ... The WMI recovery approach did not work. ... I've seen other posting/web sites suggesting that you delete the>>>Windows\system32\wbem\repository files. ... >> Please post any reply as a follow-up message in the news group ...
    (microsoft.public.windowsxp.network_web)
  • Re: Rerun an advertised program on Advanced client
    ... This info is not stored in WMI but in registry. ... This posting is provided "AS IS" with no warranties, and confers no rights. ...
    (microsoft.public.sms.swdist)