C#中如何获得磁盘驱动器的信息,比如说磁盘的剩余空间,磁盘的总空间等。
请大家帮忙
请大家帮忙
解决方案 »
- 使用ajax刷新gridview后,如何选中“刷新之前选中的行”
- 因为做了好多批量上传图片家进度条的DEMO 全部失败!!求个源码
- 判断特定的字符
- 提问:有谁知道,vs2005中的winForms 控件跟vs2003中的相比,有多大个改变?那些控件有变?多谢
- P2P资源共享问题
- 数组 二进制数组 转换问题?
- 重复输入数据,计算出涵数值.
- 大家一起谈谈校园用户帐号管理在ldap中怎样设计好?
- 紧急求助:控件截图。
- ****** 200分,如何调用自定义的 DLL .*******
- 请问:如何使用c#调用SQLSERVER的SP,使其处理大批量的数据时间最短?
- 怎样得到局域网中开有某个端口的IP列表
using System.Management;...ManagementObject disk = new
ManagementObject("win32_logicaldisk.deviceid="c:"");
disk.Get();
Console.WriteLine("Logical Disk Size = " + disk["Size"] + " bytes");
Console.WriteLine("Logical Disk FreeSpace = " + disk["FreeSpace"] + "
bytes");
public static extern bool GetDiskFreeSpaceEx(
string lpDirectoryName,
out UInt64 lpFreeBytesAvailable,
out UInt64 lpTotalNumberOfBytes,
out UInt64 lpTotalNumberOfFreeBytes);ulong freeBytesAvailable = 0;
ulong totalNumberOfBytes = 0;
ulong totalNumberOfFreeBytes = 0;GetDiskFreeSpaceEx(
"c:\\",
out freeBytesAvailable,
out totalNumberOfBytes,
out totalNumberOfFreeBytes);2. The WMI WayWe can use WMI by connecting to the “root\\cimv2” namespace and using the “Win32_LogicalDisk” class. Programming WMI isn’t pretty, but you can use the WMI extensions for VS ‘03 Server Explorer which makes it tolerable. Once installed, you’ll get a list of the management classes in server explorer and you can simply drag and drop the disk volume that you want to pull information from onto your application designer.You can then show free space on the volume with one line of code: MessageBox.Show(logicalDisk1.FreeSpace.ToString());using System;
using System.Management;tatic void Main(string[] args)
{
WqlObjectQuery wmiquery = new WqlObjectQuery("SELECT * FROM Win32_LogicalDisk WHERE DeviceID = 'C:'");
ManagementObjectSearcher wmifind = new ManagementObjectSearcher(wmiquery); foreach (ManagementObject mobj in wmifind.Get())
{
Console.WriteLine("Description: " + mobj["Description"]);
Console.WriteLine("File system: " + mobj["FileSystem"]);
Console.WriteLine("Free disk space: " + mobj["FreeSpace"]);
Console.WriteLine("Size: " + mobj["Size"]);
}
}3. The Whidbey WaySystem.IO.DriveInfo.AvailableFreeSpace
disk.Get();
MessageBox.Show("磁盘总容量:" + disk["Size"] + " bytes");
MessageBox.Show("剩余磁盘空间:" + disk["FreeSpace"] + "bytes");