By running it several times, not unexpectedly, there are noticeable, but slight fluctuations in numbers. In most cases, the Win32 API is consistent with Windows Explorer with a byte (see below). This is for a regular Windows 10 laptop, not a server. In the case of the server, I think there may be processes causing quite large fluctuations.

Sectors per Cluster: 8 Bytes Per Sector: 512 Number of Free Clusters: 126,523,800 Total Number Of Clusters: 239,423,046 Free Bytes Available: 518,241,484,800 Total Number Of Free Bytes: 518,241,484,800 Total Number Of Bytes: 980,676,796,416
Try the following:
static void Main(string[] args) { string drive = "C:"; var diskSpace = DiskHelperWin32.GetDiskFreeSpace(drive); var diskSpaceEx = DiskHelperWin32.GetDiskFreeSpaceEx(drive); Console.WriteLine("Sectors per Cluster: {0}", diskSpace.SectorsPerCluster); Console.WriteLine("Bytes Per Sector: {0}", diskSpace.BytesPerSector); Console.WriteLine("Number of Free Clusters: {0:0,0}", diskSpace.NumberOfFreeClusters); Console.WriteLine("Total Number Of Clusters: {0:0,0}", diskSpace.TotalNumberOfClusters); Console.WriteLine(); Console.WriteLine("Free Bytes Available: {0:0,0}", diskSpaceEx.FreeBytesAvailable); Console.WriteLine("Total Number Of Free Bytes: {0:0,0}", diskSpaceEx.TotalNumberOfFreeBytes); Console.WriteLine("Total Number Of Bytes: {0:0,0}", diskSpaceEx.TotalNumberOfBytes); Console.ReadLine(); }
DiskHelperWin32:
public static class DiskHelperWin32 { [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetDiskFreeSpace(string lpRootPathName, out uint lpSectorsPerCluster, out uint lpBytePerSector, out uint lpNumberOfFreeClusters, out uint lpTotalNumberOfClusters); public static DiskFreeSpace GetDiskFreeSpace(string lpRootPathName) { uint SectorsPerCluster; uint BytesPerSector; uint NumberOfFreeClusters; uint TotalNumberOfClusters; bool success = GetDiskFreeSpace(lpRootPathName, out SectorsPerCluster, out BytesPerSector, out NumberOfFreeClusters, out TotalNumberOfClusters); if (!success) throw new System.ComponentModel.Win32Exception(); return new DiskFreeSpace { BytesPerSector = BytesPerSector, SectorsPerCluster = SectorsPerCluster, NumberOfFreeClusters = NumberOfFreeClusters, TotalNumberOfClusters = TotalNumberOfClusters }; } [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes); public static DiskFreeSpaceEx GetDiskFreeSpaceEx(string lpDirectoryName) { ulong FreeBytesAvailable; ulong TotalNumberOfBytes; ulong TotalNumberOfFreeBytes; bool success = GetDiskFreeSpaceEx(lpDirectoryName, out FreeBytesAvailable, out TotalNumberOfBytes, out TotalNumberOfFreeBytes); if (!success) throw new System.ComponentModel.Win32Exception(); return new DiskFreeSpaceEx { FreeBytesAvailable = FreeBytesAvailable, TotalNumberOfFreeBytes = TotalNumberOfFreeBytes, TotalNumberOfBytes = TotalNumberOfBytes }; } }
Model:
public class DiskFreeSpace { public uint SectorsPerCluster { get; set; } public uint BytesPerSector { get; set; } public uint NumberOfFreeClusters { get; set; } public uint TotalNumberOfClusters { get; set; } } public class DiskFreeSpaceEx { public ulong FreeBytesAvailable { get; set; } public ulong TotalNumberOfBytes { get; set; } public ulong TotalNumberOfFreeBytes { get; set; } }
EDIT: Reply to the comments section.
I doubt the βproblemβ is related to any of the APIs or whether the vm server is. These numbers fluctuate even on a regular computer. For example, think of the Disk Defragmenter that appears and appears. On the server, these fluctuations can be significant, depending on what works on it. Also note the differences between FreeBytesAvailable and TotalNumberOfFreeBytes . In our case, this is a perfect match, but obviously not the rule.
Please run our MCVE sample application on your server and return with the numbers. Post them as an addition to the body of your question.