Windows Management Instrumentation (Wmi) Win32 class

Source: Internet
Author: User

A friend encountered some trouble in getting printer information and printing task queue while processing printing. I wanted to implement it using APIs. I went back to the system. Management namespace and roughly studied the system. Management namespace. I found that there are many useful functions, saving the trouble of calling APIs.
The hardware and feature information of the WMI Win32 class Monitoring and Management System. These classes are generally in the root/cimv2 WMI namespace.
Win32 has the following types:
· Computer system hardware classes

· Operating System Classes

· Installed applications classes

· WMI Service Management classes

· Performance counters classes

· Security descriptor helper class

Classes of common information are listed below:

Win32_processor// CPU Processor Win32_physicalmemory// Physical memory Win32_keyboard// Keyboard Win32_pointingdevice// Click Enter device, such as mouse Win32_diskdrive// Hard drive Win32_cdromdrive// Disc Drive Win32_baseboard// Motherboard Win32_bios// BIOS Chip Win32_parallelport// Parallel Port Win32_serialport// Serial Port Win32_sounddevice// Multimedia settings Win32_usbcontroller// USB Controller Win32_networkadapter// Network Adapter Win32_networkadapterconfiguration// Network Adapter settings Win32_printer// Printer Win32_printerconfiguration// Printer settings Win32_printjob// Printer task Win32_tcpipprinterport// Printer Port Win32_potsmodem// Modem Win32_potsmodemtoserialport// Modem Port Win32_shorttopmonitor// Display Win32_videocontroller// Video card details. Win32_videosettings// The Display Mode Supported by the video card. Win32_timezone// Time Zone Win32_systemdriver// DriverProgram Win32_diskpartition// Disk Partition Win32_logicaldisk// Logical Disk Win32_logicalmemoryconfiguration// Logical Memory Configuration Win32_pagefile// System page file information Win32_pagefilesetting// Page File Settings Win32_bootconfiguration// System startup configuration Win32_operatingsystem// Operating System Information Win32_startupcommand// The system automatically starts the program. Win32_service// System-installed services Win32_group// System Management Group Win32_groupuser// System group account Win32_useraccount// User Account Win32_process// System Process Win32_thread// System thread Win32_share// Share Win32_networkclient// Installed network client Win32_networkprotocol// Installed network protocols

The following example shows how to use a print job:
The property field of the win32_printjob class is:

Class Win32_printjob: Cim_job { StringCaption; StringColor; StringDatatype; StringDescription; StringDocument; StringDrivername; DatetimeElapsedtime; StringHostprintqueue; DatetimeInstalldate; UintJobid; StringJobstatus; StringName; StringY; StringOwner; UintPagesprinted; UintPaperlength; StringPapersize; UintPaperwidth; StringParameters; StringPrintprocessor; UintPriority; UintSize; DatetimeStarttime; StringStatus; UintStatusmask; DatetimeTimesubmitted; UintTotalpages; DatetimeUntiltime;

}

Methods of this class include:

Pause ();
Resume ();

1. SQL statement retrieval method:

Using System; Using System. Management; Class Testwmi { Public Static VoidMain () { ManagementobjectsearcherS =New Managementobjectsearcher("Select * From win32_printjob"); Foreach(ManagementobjectMInS. Get ()) { Foreach(PropertydataPInM. properties) { Console. Writeline (P. Name +"--------"+ P. value ); } } Console. Readkey (); } }

2. instantiate managementclass to obtain the managementobjectcollection method:

Using System; Using System. Management; Class Testwmi { Public Static VoidMain () { ManagementclassC =New Managementclass("Win32_printjob"); ManagementobjectcollectionCO = C. getinstances (); Foreach(ManagementobjectMInCO) { Foreach(PropertydataPInM. properties) { Console. Writeline (P. Name +"--------"+ P. value ); } } } }

. NET provides excellent packaging for Win32 WMI. The WMI programming model in. NET is surprisingly consistent, greatly reducing the coding workload and programming difficulty.
for the complete information and detailed list of WMI Win32 classes, see msdn:
http://msdn2.microsoft.com/en-us/library/aa394084 (vs.85). aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.