As you can see from Get available free disk space for this path in Windows :
Use the winapi function GetDiskFreeSpaceExto determine the free space on the UNC (network) path. For example, create a new VS project called FreeSpace and paste it as Program.cs:
using System;
using System.Runtime.InteropServices;
namespace FreeSpace
{
class Program
{
[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);
static void Main(string[] args)
{
ulong FreeBytesAvailable;
ulong TotalNumberOfBytes;
ulong TotalNumberOfFreeBytes;
bool success = GetDiskFreeSpaceEx(@"\\NETSHARE\folder",
out FreeBytesAvailable,
out TotalNumberOfBytes,
out TotalNumberOfFreeBytes);
if (!success)
throw new System.ComponentModel.Win32Exception();
Console.WriteLine("Free Bytes Available: {0,15:D}", FreeBytesAvailable);
Console.WriteLine("Total Number Of Bytes: {0,15:D}", TotalNumberOfBytes);
Console.WriteLine("Total Number Of FreeBytes: {0,15:D}", TotalNumberOfFreeBytes);
Console.ReadKey();
}
}
}
As you can see, this is the same code as in the question above, just taken into account in the class, plus the correct directives usingfor compilation without errors. All loans go to https://stackoverflow.com/users/995926/rekire
WMI, , .
Windows - :
https://msdn.microsoft.com/en-us/library/aa394592(v=vs.85).aspx