ManagementClass 无法获取磁盘分区

ManagementClass 无法获取磁盘分区,第1张

using System;

using SystemManagement; //还需要引用;

using SystemCollections;

using SystemCollectionsSpecialized;

using SystemText;

namespace WindowsFormsApplication1

{

#region WMIPath

public enum WMIPath

{

// 硬件

Win32_Processor, // CPU 处理器

Win32_PhysicalMemory, // 物理内存条

Win32_Keyboard, // 键盘

Win32_PointingDevice, // 点输入设备,包括鼠标。

Win32_FloppyDrive, // 软盘驱动器

Win32_DiskDrive, // 硬盘驱动器

Win32_CDROMDrive, // 光盘驱动器

Win32_BaseBoard, // 主板

Win32_BIOS, // BIOS 芯片

Win32_ParallelPort, // 并口

Win32_SerialPort, // 串口

Win32_SerialPortConfiguration, // 串口配置

Win32_SoundDevice, // 多媒体设置,一般指声卡。

Win32_SystemSlot, // 主板插槽 (ISA & PCI & AGP)

Win32_USBController, // USB 控制器

Win32_NetworkAdapter, // 网络适配器

Win32_NetworkAdapterConfiguration, // 网络适配器设置

Win32_Printer, // 打印机

Win32_PrinterConfiguration, // 打印机设置

Win32_PrintJob, // 打印机任务

Win32_TCPIPPrinterPort, // 打印机端口

Win32_POTSModem, // MODEM

Win32_POTSModemToSerialPort, // MODEM 端口

Win32_DesktopMonitor, // 显示器

Win32_DisplayConfiguration, // 显卡

Win32_DisplayControllerConfiguration, // 显卡设置

Win32_VideoController, // 显卡细节。

Win32_VideoSettings, // 显卡支持的显示模式。

// *** 作系统

Win32_TimeZone, // 时区

Win32_SystemDriver, // 驱动程序

Win32_DiskPartition, // 磁盘分区

Win32_LogicalDisk, // 逻辑磁盘

Win32_LogicalDiskToPartition, // 逻辑磁盘所在分区及始末位置。

Win32_LogicalMemoryConfiguration, // 逻辑内存配置

Win32_PageFile, // 系统页文件信息

Win32_PageFileSetting, // 页文件设置

Win32_BootConfiguration, // 系统启动配置

Win32_ComputerSystem, // 计算机信息简要

Win32_OperatingSystem, // *** 作系统信息

Win32_StartupCommand, // 系统自动启动程序

Win32_Service, // 系统安装的服务

Win32_Group, // 系统管理组

Win32_GroupUser, // 系统组帐号

Win32_UserAccount, // 用户帐号

Win32_Process, // 系统进程

Win32_Thread, // 系统线程

Win32_Share, // 共享

Win32_NetworkClient, // 已安装的网络客户端

Win32_NetworkProtocol, // 已安装的网络协议

}

#endregion

/// <summary>

/// 获取系统信息

/// </summary>

/// <example>

/// <code>

/// WMI w = new WMI(WMIPathWin32_NetworkAdapterConfiguration);

/// for (int i = 0; i < wCount; i ++)

/// {

/// if ((bool)w[i, "IPEnabled"])

/// {

/// ConsoleWriteLine("Caption:{0}", w[i, "Caption"]);

/// ConsoleWriteLine("MAC Address:{0}", w[i, "MACAddress"]);

/// }

/// }

/// </code>

/// </example>

public sealed class WMI

{

private ArrayList mocs;

private StringDictionary names; // 用来存储属性名,便于忽略大小写查询正确名称。

/// <summary>

/// 信息集合数量

/// </summary>

public int Count

{

get { return mocsCount; }

}

/// <summary>

/// 获取指定属性值,注意某些结果可能是数组。

/// </summary>

public object this[int index, string propertyName]

{

get

{

try

{

string trueName = names[propertyNameTrim()]; // 以此可不区分大小写获得正确的属性名称。

Hashtable h = (Hashtable)mocs[index];

return h[trueName];

}

catch

{

return null;

}

}

}

/// <summary>

/// 返回所有属性名称。

/// </summary>

/// <param name="index"></param>

/// <returns></returns>

public string[] PropertyNames(int index)

{

try

{

Hashtable h = (Hashtable)mocs[index];

string[] result = new string[hKeysCount];

hKeysCopyTo(result, 0);

ArraySort(result);

return result;

}

catch

{

return null;

}

}

/// <summary>

/// 返回测试信息。

/// </summary>

/// <returns></returns>

public string Test()

{

try

{

StringBuilder result = new StringBuilder(1000);

for (int i = 0; i < Count; i++)

{

int j = 0;

foreach (string s in PropertyNames(i))

{

resultAppend(stringFormat("{0}:{1}={2}\n", ++j, s, this[i, s]));

if (this[i, s] is Array)

{

Array v1 = this[i, s] as Array;

for (int x = 0; x < v1Length; x++)

{

resultAppend("\t" + v1GetValue(x) + "\n");

}

}

}

resultAppend("======WMI=======\n");

}

return resultToString();

}

catch

{

return stringEmpty;

}

}

/// <summary>

/// 构造函数

/// </summary>

/// <param name="path"></param>

public WMI(string path)

{

names = new StringDictionary();

mocs = new ArrayList();

try

{

ManagementClass cimobject = new ManagementClass(path);

ManagementObjectCollection moc = cimobjectGetInstances();

bool ok = false;

foreach (ManagementObject mo in moc)

{

Hashtable o = new Hashtable();

mocsAdd(o);

foreach (PropertyData p in moProperties)

{

oAdd(pName, pValue);

if (!ok) namesAdd(pName, pName);

}

ok = true;

moDispose();

}

mocDispose();

}

catch (Exception e)

{

throw new Exception(eMessage);

}

}

/// <summary>

/// 构造函数

/// </summary>

/// <param name="path"></param>

public WMI(WMIPath path)

: this(pathToString())

{

}

}

}

Visual Studio(VS)是一款常用的集成开发环境,它提供了强大的代码编写环境、调试功能、部署功能等方面的支持。通常是把新项目放在D盘,而不是放在系统默认目录,因为创建新项目时,VS会在此文件夹中创建各种文件,因此把新项目放在D盘可以有效减少文件的混乱,提高工作效率。此外,D盘的读写速度比C盘要快,有利于程序的即时性和运行效率,而不会造成硬件设备的磨损。在VS中,可以通过“文件”-“新建”-“项目”来设置新项目存储位置。

1、现在还是台式机的35寸硬盘容量比较大,从160G-2TB都有,移动硬盘800G的占主流没听说过,因为没有800GB这一说,连台式机硬盘也没听说过有800GB容量的,一般是80、160/250/320/500/640GB/1TB和2TB。

2、现在移动硬盘的主流也就是在160GB和320GB最多500GB是主流,1TB的很少用,毕竟大多数人没有那么多海量数据传输需要。

技术上足够了,但是除了服务器海量存储需要,很少有人用TB级的硬盘,考虑到性价比和存储量的需要,500GB是主流。

希捷硬盘有vx和vm两种规格。

vx硬盘,ST3000VX000,7200转/s,属于标清盘,一般用于监控。

vm硬盘,ST3000VM002,5400转/s,属于高清盘。

以上就是关于ManagementClass 无法获取磁盘分区全部的内容,包括:ManagementClass 无法获取磁盘分区、vs为什么在d盘放新项目、电脑硬盘vs移动硬盘等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/10081756.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存