Windows Management Instrumentation(WMI) 之 Win32 类
来源:互联网 发布:mac桌面消失 编辑:程序博客网 时间:2024/05/01 06:11
在处理打印时,获得打印机信息和打印任务队列时遇到了点麻烦。本想用API实现,回去粗略研究了下 System.Management 命名空间,发现这里面有相当多有用的功能,省去了调用API的麻烦。
WMI中的Win32类监控和管理系统的硬件和特征信息,这些类一般在root/cimv2 WMI 命名空间中。
Win32类主要有一下几类:
·Computer System Hardware Classes
·Operating System Classes
·Installed Applications Classes
·WMI Service Management Classes
·Performance Counters Classes
·Security Descriptor Helper Class
下面列出了常用信息的类:
Win32_Processor // CPU 处理器
Win32_PhysicalMemory // 物理内存
Win32_Keyboard // 键盘
Win32_PointingDevice // 点输入设备,如鼠标
Win32_DiskDrive // 硬盘驱动器
Win32_CDROMDrive // 光盘驱动器
Win32_BaseBoard // 主板
Win32_BIOS // BIOS 芯片
Win32_ParallelPort // 并口
Win32_SerialPort // 串口
Win32_SoundDevice // 多媒体设置
Win32_USBController // USB 控制器
Win32_NetworkAdapter // 网络适配器
Win32_NetworkAdapterConfiguration // 网络适配器设置
Win32_Printer // 打印机
Win32_PrinterConfiguration // 打印机设置
Win32_PrintJob // 打印机任务
Win32_TCPIPPrinterPort // 打印机端口
Win32_POTSModem // MODEM
Win32_POTSModemToSerialPort // MODEM 端口
Win32_DesktopMonitor // 显示器
Win32_VideoController // 显卡细节。
Win32_VideoSettings // 显卡支持的显示模式。
Win32_TimeZone // 时区
Win32_SystemDriver // 驱动程序
Win32_DiskPartition // 磁盘分区
Win32_LogicalDisk // 逻辑磁盘
Win32_LogicalMemoryConfiguration // 逻辑内存配置
Win32_PageFile // 系统页文件信息
Win32_PageFileSetting // 页文件设置
Win32_BootConfiguration // 系统启动配置
Win32_OperatingSystem // 操作系统信息
Win32_StartupCommand // 系统自动启动程序
Win32_Service // 系统安装的服务
Win32_Group // 系统管理组
Win32_GroupUser // 系统组帐号
Win32_UserAccount // 用户帐号
Win32_Process // 系统进程
Win32_Thread // 系统线程
Win32_Share // 共享
Win32_NetworkClient // 已安装的网络客户端
Win32_NetworkProtocol // 已安装的网络协议
以获得打印作业为例演示一下其使用方法:
Win32_PrintJob类的属性字段为:
class Win32_PrintJob : CIM_Job
{
string Caption;
string Color;
string DataType;
string Description;
string Document;
string DriverName;
DateTime ElapsedTime;
string HostPrintQueue;
DateTime InstallDate;
uint JobId;
string JobStatus;
string Name;
string Notify;
string Owner;
uint PagesPrinted;
uint PaperLength;
string PaperSize;
uint PaperWidth;
string Parameters;
string PrintProcessor;
uint Priority;
uint Size;
DateTime StartTime;
string Status;
uint StatusMask;
DateTime TimeSubmitted;
uint TotalPages;
DateTime UntilTime;
}
该类的方法有:
Pause();
Resume();
1.SQL语句检索方法:
using System;
using System.Management;
class TestWMI
{
public static void Main()
{
ManagementObjectSearcher s = new ManagementObjectSearcher("SELECT * FROM Win32_PrintJob");
foreach (ManagementObject m in s.Get())
{
foreach (PropertyData p in m.Properties)
{
Console.WriteLine(p.Name + "--------" + p.Value);
}
}
Console.ReadKey();
}
}
2.实例化ManagementClass,获得ManagementObjectCollection方法:
using System;
using System.Management;
class TestWMI
{
public static void Main()
{
ManagementClass c = new ManagementClass("Win32_PrintJob");
ManagementObjectCollection co = c.GetInstances();
foreach (ManagementObject m in co)
{
foreach (PropertyData p in m.Properties)
{
Console.WriteLine(p.Name + "--------" + p.Value);
}
}
}
}
.NET对Win32 WMI进行了精彩的包装,.NET 中 WMI 的编程模型出奇的一致,大大减少了编码量和编程难度。
WMI Win32类的完整信息及详细列表请参考MSDN:
http://msdn2.microsoft.com/en-us/library/aa394084(VS.85).aspx
- Windows Management Instrumentation(WMI) 之 Win32 类
- Windows Management Instrumentation(WMI) 之 Win32 类
- Windows Management Instrumentation(WMI) 之 Win32 类
- Windows Management Instrumentation (WMI)
- Windows Management Instrumentation(WMI)
- WMI (Windows Management Instrumentation) - Secrets
- WMI 编程 (Windows Management Instrumentation)
- Developing WMI Solutions: A Guide to Windows Management Instrumentation
- Windows Management Instrumentation (WMI)信息可能损坏错误修复
- 安装SQL Server2014 :规则”Windows Management Instrumentation (WMI)服务 “失败
- 解决【Windows Management Instrumentation(WMI)信息可能损坏】
- Windows Management Instrumentation
- 8. Windows Management Instrumentation
- WMI003-WMI学习笔记(三)——Windows Management Instrumentation(Windows管理工具)
- windows不能显示此连接属性。windows management instrumentation (WMI) 信息可能损坏
- WMI之Win32硬件类
- Windows Management Instrumentation无法启动
- Windows Management Instrumentation (Windows 管理规范)
- Swing实现选项卡功能(JTabbedPane)
- mini2440 u-boot-2009.03 移植最详细攻略
- 百度空间的访问统计怎么做
- A CSS styled table
- 一个问题的长征
- Windows Management Instrumentation(WMI) 之 Win32 类
- JavaBean中打印信息到JSP页面
- 指针概述
- To be a senior software engineer【3】(QT+openGL)
- 本人对经济的看法
- 强烈推荐:右左法则----复杂指针解析
- 在选项卡设置提示信息
- C语言的谜题
- To be a senior software engineer【4】(QT+openGL)