VC calls WMI framework

Source: Internet
Author: User
Tags snmp

An example of Microsoft msdn
Compiled and tested in vc6

# Include <afx. h> // use the cstring BSTR to convert it to ANSI # DEFINE _ win32_dcom // this bug does not understand // vc6. so standard STL is useless .. # include <iostream. h> # include <iomanip. h> // using namespace STD; // COM component # include <comdef. h> # include <wbemidl. h> # pragma comment (Lib, "wbemuuid. lib ") int main (INT argc, char ** argv) {hresult hres; // defines the return of the com call // Step 1: ---------------------------------------------------- // initialize COM. ------------------------- ----------------- Hres = coinitializeex (0, coinit_multithreaded); If (failed (hres) {cout <"failed to initialize com library. error code = 0x "

A vbs with the same function...

strComputer = "."   ' Dot (.) equals local computer in WMISet wbemServices = Getobject("winmgmts:\\" & strComputer)Set wbemObjectSet = wbemServices.InstancesOf("Win32_Process")For Each wbemObject In wbemObjectSet    WScript.Echo "Name:       " & wbemObject.Name      & vbCrLf & _                 "Handle:     " & wbemObject.Handle    & vbCrLf & _                 "Process ID: " & wbemObject.ProcessIDNext

Enumeration namespace

strComputer = "."Call EnumNameSpaces("root")Sub EnumNameSpaces(strNameSpace)  WScript.Echo strNameSpace  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)  Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")  For Each objNameSpace In colNameSpaces    Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)  NextEnd Sub

Use WMI and VBScript to set the script's default namespace

strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colWMISettings = objWMIService.InstancesOf("Win32_WMISetting")For Each objWMISetting in colWMISettings        objWMISetting.ASPScriptDefaultNamespace = "root\cimv2"        objWMISetting.Put_Next

Use WMI and VBScript to retrieve CIM namespaces

strComputer = "."Set objServices = GetObject("winmgmts:\\" & strComputer & "\root")Set colNameSpaces = objServices.InstancesOf("__NAMESPACE")For Each objNameSpace In colNameSpaces    WScript.Echo objNameSpace.NameNext

Use WMI and VBScript to retrieve all CIM namespaces

strComputer = "."Call EnumNameSpaces("root")Sub EnumNameSpaces(strNameSpace)  WScript.Echo strNameSpace  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)  Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")  For Each objNameSpace In colNameSpaces    Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)  NextEnd Sub

Use WMI and VBScript to retrieve Win32 providers registered in the Root \ cimv2 namespace

strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colWin32Providers = objWMIService.InstancesOf("__Win32Provider")For Each objWin32Provider In colWin32Providers    WScript.Echo objWin32Provider.NameNext

Use WMI and VBScript to retrieve all classes defined in the Root \ cimv2 namespace

strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colClasses = objWMIService.SubclassesOf()For Each objClass In colClasses    WScript.Echo objClass.Path_.PathNext

// Specific WQL instance

objSWbemServices.ExecQuery("SELECT * FROM Win32_Service")objSWbemServices.ExecQuery("SELECT Name FROM Win32_Service")objSWbemServices.ExecQuery("SELECT StartMode FROM Win32_Service")objSWbemServices.ExecQuery("SELECT StartMode FROM Win32_Service WHERE State='Running'")objSWbemServices.ExecQuery("SELECT StartMode, State FROM Win32_Service WHERE State='Running'")objSWbemServices.ExecQuery("SELECT * FROM Win32_Service WHERE Name='WinMgmt'")objSWbemServices.Get("Win32_Service.Name='WinMgmt'")

Below are some WMI query information

Description of the provided program DLL namespace

Active Directory provider
Dsprov. dll
Root \ directory \ LDAP
Map an Active Directory object to WMI.

Event Log provider
Ntevt. dll
Root \ cimv2
Manage Windows event logs, such as reading, backing up, clearing, copying, deleting, monitoring, renaming, compressing, extracting, and changing event log settings.

Performance Counter provider
Wbemperf. dll
Root \ cimv2
Provides access to raw performance data.

Registry provider
Stdprov. dll
Root \ default
Read, write, enumerate, monitor, create, and delete registry entries and values.

SNMP provider
Snmpincl. dll
Root \ SNMP
Access the snmp mib Data and capture the data from the SNMP hosting device.

WDM providers
Wmiprov. dll
Root \ WMI
Provides access to information in the driver of the WDM device.

Win32 provider
Cimwin32.dll
Root \ cimv2
Provides information about computers, disks, peripheral devices, files, folders, file systems, network components, operating systems, printers, processes, security, services, sharing, Sam users, and groups, and more resource information.

Windows Installer provider
Msiprov. dll
Root \ cimv2
Provide access to installed software information.

Win32_processor // CPU Processor

Win32_physicalmemory // physical memory

Win32_keyboard // keyboard

Win32_pointingdevice // enter the device, such as the mouse

Win32_diskdrive // hard drive

Win32_cdromdrive // Optical 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_desktopmonitor // display

Win32_videocontroller // graphics card details.

Win32_videosettings // Display Mode Supported by the video card.

Win32_timezone // Time Zone

Win32_systemdriver // driver

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 Service

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 protocol

Brwin32_pagefilesetting // page File Settings

The following is an example: JS uses WMI to obtain computer hardware information.

For example, to obtain the hard disk serial number:

<HTML> 

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.