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