George:
This is what I found in MS and quote "
After consulting, I was told that WMI will internally use
GetDiskFreeSpace() API function. While GetDiskFreeSpace is processed by
CDFS, which is a read-only filesystem. So the return value of Free Space is
always 0.
To workaround your issue, we need to use Image Mastering API(IMAPI) to get
this done. I will spend some more time on IMAPI to resolve your issue.
"
in the second post he post a C# code that follow"
using System;
using System.Runtime.InteropServices;
namespace Interop_IMAPI
{
///
/// Summary description for Class1.
/// class Class1
{
///
/// The main entry point for the application.
/// [STAThread]
static void Main(string[] args)
{
const int S_FALSE = 1;
const int S_OK = 0;
IDiscMaster idm = null;
IDiscRecorder idr = null;
IEnumDiscRecorders iedr = null;
DiscMaster dm = new DiscMaster();
idm = dm as IDiscMaster;
if (idm != null)
Console.WriteLine("IDiscMaster cast succeed");
idm.Open();
uint celt;
idm.EnumDiscRecorders(out iedr);
byte sessions;
byte lastTrack;
uint startAddress;
uint nextWritableBlock;
uint freeBlocks;
string path = string.Empty;
uint freeBytes;
uint usedBytes;
uint totalBytes;
const uint BLOCK_SIZE = 2048; // Data CDs use 2048-byte sectors.
if (iedr != null)
Console.WriteLine("IEnumDiscRecorders get ok");
while ( S_FALSE != iedr.Next(1,out idr, out celt))
{
if (idr != null)
Console.WriteLine("IDiscRecorders get ok");
idr.GetPath(path);
idr.OpenExclusive();
int hr = idr.QueryMediaInfo(out sessions,out lastTrack,out
startAddress,out nextWritableBlock, out freeBlocks);
if ( S_OK == hr )
{
freeBytes = freeBlocks * BLOCK_SIZE;
usedBytes = nextWritableBlock * BLOCK_SIZE;
totalBytes = freeBytes + usedBytes;
Console.WriteLine("Free Space = {0} MB {1}
bytes",freeBytes/(1024*1024), freeBytes);
Console.WriteLine("Used Space = {0} MB {1}
bytes",usedBytes/(1024*1024), usedBytes);
Console.WriteLine("Total capacity = {0} MB {1} bytes",
totalBytes/(1024*1024), totalBytes);
Console.WriteLine();
}
else
{
Console.WriteLine("IDiscRecorder.QueryMediaInfo failed HRESULT = {0}",
hr);
}
Marshal.ReleaseComObject(idr);
}
idm.Close();
Console.WriteLine("end");
}
}
#region original typedef
/*
// * MIDL_INTERFACE("520CCA62-51A5-11D3-9144-00104BA11C5E")
// IDiscMaster : public IUnknown
// {
// public:
// virtual /* [helpstring] */ //HRESULT STDMETHODCALLTYPE Open(
void) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
EnumDiscMasterFormats(
// /* [out] */ IEnumDiscMasterFormats **ppEnum) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
GetActiveDiscMasterFormat(
// /* [out] */ LPIID lpiid) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
SetActiveDiscMasterFormat(
// /* [in] */ REFIID riid,
// /* [iid_is][out] */ void **ppUnk) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE EnumDiscRecorders(
// /* [out] */ IEnumDiscRecorders **ppEnum) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
GetActiveDiscRecorder(
// /* [out] */ IDiscRecorder **ppRecorder) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
SetActiveDiscRecorder(
// /* [in] */ IDiscRecorder *pRecorder) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE ClearFormatContent(
void) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE ProgressAdvise(
// /* [in] */ IDiscMasterProgressEvents *pEvents,
// /* [retval][out] */ UINT_PTR *pvCookie) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE ProgressUnadvise(
// /* [in] */ UINT_PTR vCookie) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE RecordDisc(
// /* [in] */ boolean bSimulate,
// /* [in] */ boolean bEjectAfterBurn) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Close( void) = 0;
//};*/
#endregion
[
ComImport(),
Guid("520CCA62-51A5-11D3-9144-00104BA11C5E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
interface IDiscMaster
{
void Open();
void EnumDiscMasterFormats(out IntPtr ppEnum);
void GetActiveDiscMasterFormat(ref Guid lpiid);
void SetActiveDiscMasterFormat(Guid riid, IntPtr ppUnk);
void EnumDiscRecorders(out IEnumDiscRecorders ppEnum);
void GetActiveDiscRecorder( out IDiscRecorder ppRecorder);
void SetActiveDiscRecorder(IDiscRecorder pRecorder);
void ClearFormatContext();
void ProgressAdvise(IntPtr pEvents, IntPtr pvCookie);
void ProgressUnadvise( IntPtr vCookie);
void RecordDisc(bool bSimulate, bool bEjectAfterBurn);
void Close();
}
#region original definition
// MIDL_INTERFACE("9B1921E1-54AC-11d3-9144-00104BA11C5E")
// IEnumDiscRecorders : public IUnknown
// {
// public:
// virtual HRESULT STDMETHODCALLTYPE Next(
// /* [in] */ ULONG cRecorders,
// /* [length_is][size_is][out] */ IDiscRecorder **ppRecorder,
// /* [out] */ ULONG *pcFetched) = 0;
//
// virtual HRESULT STDMETHODCALLTYPE Skip(
// /* [in] */ ULONG cRecorders) = 0;
//
// virtual HRESULT STDMETHODCALLTYPE Reset( void) = 0;
//
// virtual HRESULT STDMETHODCALLTYPE Clone(
// /* [out] */ IEnumDiscRecorders **ppEnum) = 0;
//
// };
#endregion
[
ComImport(),
Guid("9B1921E1-54AC-11d3-9144-00104BA11C5E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
interface IEnumDiscRecorders
{
[PreserveSig]
int Next(uint cRecorders, out IDiscRecorder ppRecorder, out uint
pcFetched);
void Skip(uint cRecorders);
void Reset();
void Clone(out IEnumDiscRecorders ppEnum);
}
#region definition
// MIDL_INTERFACE("85AC9776-CA88-4cf2-894E-09598C078A41")
// IDiscRecorder : public IUnknown
// {
// public:
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Init(
// /* [size_is][in] */ byte *pbyUniqueID,
// /* [in] */ ULONG nulIDSize,
// /* [in] */ ULONG nulDriveNumber) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetRecorderGUID(
// /* [size_is][unique][out][in] */ byte *pbyUniqueID,
// /* [in] */ ULONG ulBufferSize,
// /* [out] */ ULONG *pulReturnSizeRequired) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetRecorderType(
// /* [out] */ long *fTypeCode) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetDisplayNames(
// /* [unique][out][in] */ BSTR *pbstrVendorID,
// /* [unique][out][in] */ BSTR *pbstrProductID,
// /* [unique][out][in] */ BSTR *pbstrRevision) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetBasePnPID(
// /* [out] */ BSTR *pbstrBasePnPID) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetPath(
// /* [out] */ BSTR *pbstrPath) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
GetRecorderProperties(
// /* [out] */ IPropertyStorage **ppPropStg) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE
SetRecorderProperties(
// /* [in] */ IPropertyStorage *pPropStg) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE GetRecorderState(
// /* [out] */ ULONG *pulDevStateFlags) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE OpenExclusive(
void) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE QueryMediaType(
// /* [out] */ long *fMediaType,
// /* [out] */ long *fMediaFlags) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE QueryMediaInfo(
// /* [out] */ byte *pbSessions,
// /* [out] */ byte *pbLastTrack,
// /* [out] */ ULONG *ulStartAddress,
// /* [out] */ ULONG *ulNextWritable,
// /* [out] */ ULONG *ulFreeBlocks) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Eject( void) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Erase(
// /* [in] */ boolean bFullErase) = 0;
//
// virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE Close( void) = 0;
//
// };
#endregion
[
ComImport(),
Guid("85AC9776-CA88-4cf2-894E-09598C078A41"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
]
interface IDiscRecorder
{
void Init( IntPtr pbyUniqueID, uint nulIDSize, uint nulDriveNumber);
void GetRecorderGUID( IntPtr pbyUniqueID, uint ulBufferSize, uint
pulReturnSizeRequired);
void GetRecorderType( out long fTypeCode);
void GetDisplayNames( [In,Out] string pbstrVenderID, [In,Out] string
pbstrProductID,
[In,Out] string pbstrRevision);
void GetBasePnPID( [Out] string pbstrBasePnPID);
void GetPath( [Out] string pbStrPath);
void GetRecorderProperties( out IntPtr ppPropStg);
void SetRecorderProperties( out IntPtr pPropStg);
void GetRecorderState(out uint pulDevStateFlags);
void OpenExclusive();
void QueryMediaType( out uint fMediaType, out uint fMediaFlags);
[PreserveSig]
int QueryMediaInfo( out byte pbSessions, out byte pbLastTrack,
out uint ulStartAddress, out uint ulNextWritable,out uint ulFreeBlocks);
void Eject();
void Erase( bool bFullErase);
void Close();
}
[
ComImport,
Guid("520CCA63-51A5-11D3-9144-00104BA11C5E")
]
class DiscMaster
{
}
}
I am not familiar with this code so if you know any function that I can call from VFP to do the same let me know.