如何使用c#获取远程机器的可用磁盘空间? [英] How to get the free disk space of a remote machine using c#?
本文介绍了如何使用c#获取远程机器的可用磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用c#获取远程计算机的可用磁盘空间?我是通过c#中的windows应用程序这样做的。
我可以通过以下代码获取系统的磁盘空间
How to get the free disk space of a remote machine using c#? I am doing so via windows application in c#.
I am able to get the disk space of my system with below code
//Check whether the Drive Fetched from App.Config exists in the system
if (Environment.SystemDirectory.Contains(DBDriveName) == true)
{
//Fetch the Drive Name exists with that in the App.Config and see there is enough space to create DB Back Up
foreach (DriveInfo drivename in DriveInfo.GetDrives())
{
//Fetching the free space of the drive from App.Config if existing and obtaining the same in MB
if (drivename.IsReady && drivename.Name == DBDriveName)
{
TotalDiskFreeSpace = drivename.TotalFreeSpace / (1024 * 1024);
}
}
}
else
{
//Pass the msg if drive is not exisiting fetched from App.Config
DbBackUpStatus = "Drive doesn't Exist";
}
推荐答案
GetDiskFreeSpaceEx
似乎是您最好的选择。
/ ravi
GetDiskFreeSpaceEx
seems like your best bet.
/ravi
你好,
您可以使用上面相同的代码来获得可用空间映射驱动器;但是,出于显而易见的原因,不建议共享根文件夹。如果你有一个共享文件夹我相信上面的代码只会显示该卷的配额而不是整个驱动器。
干杯
Hello,
You could use the same code above to get the free space of a mapped drive; however, sharing the root folder would not be recommended for obvious reasons. if you had a shared folder i believe the above code would only show you the quota set for that volume and not the entire drive.
Cheers
这篇关于如何使用c#获取远程机器的可用磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文