Developing WMI Solutions: A Guide to Windows Management Instrumentation

Book description

"Craig and Gwyn bring their insight and experience with WMI to explain how easy it is to write powerful management applications through WMI on the .NET platform."

—Andy Cheung, Microsoft WMI Test Engineer

Windows Management Instrumentation (WMI) is an impressive technology that provides, for the first time, an integrated approach to hardware and software management for the Windows operating system. Developing WMI Solutions gives administrators and developers the skills necessary to take advantage of the power of WMI with Windows 2000, XP, and .NET Server.

Developing WMI Solutions starts with an overview of the concepts behind systems management. The authors then provide a synopsis of existing management architectures, as well as an explanation of the architectural components of WMI and the tools provided by Microsoft for their use. Also included is a WMI scripting boot camp for administrators using samples in VBScript, plus a series of best practices that give scripts a professional edge.

You will find thorough coverage of such topics as:

  • The Common Information Model (CIM)

  • Developing CIM extended schemas

  • Management-application development using C++ and COM for WMI

  • MMC snap-in development using C++ and COM, presented as a tutorial

  • WMI providers and the necessary C++ and COM skills needed to expose class schema

  • Developing management applications using the .NET Framework—the first comprehensive guide to the WMI classes in the System.Management namespace

  • Finally, developers will learn about the often undersold but extremely powerful high-performance event-tracing mechanism available in Windows, which allows developers to expose detailed information about operations in an application.

    The companion Web site, located at http://www.wbem.co.uk, includes the complete set of code examples found in the book, as well as updates and related articles.

    Both a tutorial and a reference, Developing WMI Solutions is an essential companion for network administrators, software developers, and team leaders looking to become proficient with WMI.



    0201616130B10072002

    Table of contents

    1. Copyright
    2. Preface
      1. Who Is This Book for and What Is WMI?
      2. How to Approach This Book and What You Will Learn
        1. Chapter 1: Introduction
        2. Chapter 2: Existing Management Frameworks
        3. Chapter 3: Windows Management Instrumentation
        4. Chapter 4: A Guided Tour of the Common Information Model Repository
        5. Chapter 5: Developing Class Schemas
        6. Chapter 6: Method Design and Schema Class Positioning
        7. Chapter 7: Developing Management Applications
        8. Chapter 8: Developing .NET Management Applications
        9. Chapter 9: Developing MMC Snap-ins
        10. Chapter 10: Developing WMI Scripts for Administrators
        11. Chapter 11: WMI Scripting and WMIC
        12. Chapter 12: Developing WMI Providers
        13. Chapter 13: High-Performance Instrumentation
        14. Where Can I Find the Sample Source Code and Scripts?
        15. Glossary
      3. Acknowledgments
        1. Craig Tunstall
        2. Gwyn Cole
    3. 1. Introduction
      1. Structure of the Book
      2. Pedagogical Elements
      3. Target Audience
      4. Prerequisites
      5. Terminology
      6. Software Requirements
      7. Operating System Requirements
      8. Hardware Requirements
      9. Introducing WBEM
      10. WBEM's Basic Objectives
      11. Core Objectives
      12. The Central Information Store
      13. The Common Information Model
      14. Object Orientation and CIM
      15. Building an Information Model
      16. Structure of the Centralized Repository
      17. The Three-Tiered Model
      18. Acronyms and Terminology
      19. Standards Bodies
      20. Motivation
      21. De Facto and de Jure Standards
      22. The Distributed Management Task Force (DMTF)
      23. The World Wide Web Consortium (W3C)
      24. Web-Based Enterprise Management (WBEM)
      25. Windows Management Instrumentation (WMI)
      26. Common Information Model (CIM)
      27. Common Information Model (CIM) Repository
      28. Managed Object Format (MOF)
      29. Simple Network Management Protocol (SNMP)
      30. Common Management Information Services (CMIS)
      31. Common Management Information Protocol (CMIP)
      32. Desktop Management Interface (DMI)
      33. eXtensible Markup Language (XML)
      34. Hypertext Transfer Protocol (HTTP)
      35. Extended Schemas
      36. WMI Scripting
      37. Summary
    4. 2. Existing Management Frameworks
      1. New and Old Technologies Combined
      2. The Need for a Universal Management Model
      3. The Simple Network Management Protocol
      4. A Simple Solution to a Complex Problem
      5. The SNMP Network Management Station
      6. Relevant SNMP Standards
      7. Structure of an SNMP Message
      8. Communities
      9. Event Notification: SNMP Traps and Informs
      10. The Management Information Base
      11. SNMP Security
      12. Modus Operandi
      13. Advantages of the SNMP Protocol
      14. Disadvantages of the SNMP Protocol
      15. The Desktop Management Interface
      16. The DMI Information Model: The Management Store
      17. Policy
      18. Notification of Events
      19. DMI Security
      20. MIF Database Security
      21. Management Interface Security
      22. Component Interface Security
      23. Security Indications
      24. Advantages of the DMI
      25. Disadvantages of the DMI
      26. Summary
        1. Common Elements for Management Frameworks
        2. The Need for a Unified Management Framework
    5. 3. Windows Management Instrumentation
      1. The Standard WBEM Components
      2. Installing WMI
        1. Installation Files
          1. Core (WMICORE.EXE) (approximately 6.5 Mb)
          2. WMI SDK (WMISDK.EXE) (approximately 12Mb)
        2. Configuring Windows 98 for WMI
          1. Optional Setting
      3. Core Components of WMI
        1. winMgmt.exe: The Windows Management Service
        2. mofcomp.exe: The Microsoft MOF Compiler
        3. The WMI Control
        4. Windows Management Instrumentation Tester
        5. Automatic MOF Registration
        6. WMI Log Files
        7. WMI CIM Repository
      4. Windows Management Instrumentation
        1. The Basic Framework of WMI
      5. WMI Management Applications
        1. Direct Access
        2. Indirect Access
        3. Providers
      6. Types of Providers
        1. Event Providers
        2. Data Providers
      7. Event Handling
        1. Intrinsic Events
        2. Extrinsic Events
        3. Timer Events
      8. Event Consumer
        1. Temporary Consumers
        2. Permanent Consumers
      9. WMI Security
        1. Authentication
        2. WMI Permission Assignment Using WMI Control
          1. WMI Security on Windows 9x
      10. The WMI Query Language
        1. Data Queries
        2. Event Queries
        3. Schema Queries
      11. Summary
    6. 4. A Guided Tour of the Common Information Model Repository
      1. Metadata
      2. Dynamic and Static Data
      3. Dynamic Data and the CIM Repository
      4. The Common Information Model
        1. The Core Model
        2. The Common Model
          1. Systems Model
          2. Networks Model
          3. Devices Model
          4. Physical Model
          5. Applications Model
          6. Event Model
          7. Policy Model
          8. Support Model
          9. User Model
          10. Metrics Model
          11. Interop Model
        3. The Extended Schemas
      5. Namespaces
      6. Using the CIMV2 Namespace
      7. WMI Namespaces and the CIM repository
      8. Defining and Using Your Own Namespace
      9. Namespaces and Schemas
      10. Using Existing Schemas
      11. Subclassing and Instantiating Existing Classes in the CIMV2 Namespace
      12. Modifying Existing Classes
        1. Managed Object Format
      13. MOF Class Declaration
      14. Qualifiers
      15. Flavors
      16. Custom Qualifiers
      17. User-Defined Qualifiers
      18. Intrinsic Data Types
      19. Instance Creation
        1. Aliasing
      20. A Compileable MOF File
      21. ActiveX Components
      22. Let the Tour Begin!
      23. The Class Explorer Explained
        1. Associations
        2. Key Propagation
        3. Namespaces and Associations
      24. System Properties
      25. Object and Property Qualifiers
      26. CIM Studio Functions
        1. Help for a Class
        2. Browse for a Namespace
        3. Search for a Class
        4. Instance Enumeration
        5. Change the View (System Properties and Inherited Properties)
        6. WQL Queries Tool
        7. Add a Class
        8. Create an Association
        9. Delete a Class or Association
        10. Delete a Property
        11. Add an Instance
        12. Delete an Instance
      27. Places of Interest within the CIM repository
        1. The Provider Classes
        2. The Namespace Classes
        3. Create a Namespace
        4. Delete a Namespace
      28. Tutorial: Creating a Namespace and Adding Classes, Properties, and an Association
      29. The Wizards
        1. The MOF Generator
        2. The MOF Compiler
        3. The Provider Code Generator
      30. Summary
    7. 5. Developing Class Schemas
      1. Schema Design and System Manageability
      2. Case Study: Client/Server E-mail Package
        1. Basic Functionality
        2. System Requirements for Post Office E-mail
      3. The Unified Modeling Language
        1. Further Reading in UML
      4. Learning the CIM Schema and Win32 Extended Schemas
        1. Psychological Requirements
        2. Schema Design Timescales
        3. Software Application Life Cycle
      5. The Windows Installer and WMI
        1. The Role of WMI with Standard Software Applications and Management Software Applications
      6. Schema Design by Teams vs. by Single Developers
        1. When Should I Commit My Design to UML?
        2. Can I Design a Schema without UML?
      7. The Unified Modeling Language in Schema Design
      8. A Brief Introduction to UML Object Modeling
        1. Inheritance Notation
        2. Association Notation
        3. Aggregate Associations
      9. Interpreting the Common Model in UML
      10. The Schema Design Road Map
        1. Basic Rules for Schema Design
          1. Telephone Operator Example
      11. WMI Topology Design
        1. First Approach
        2. Second Approach
      12. Schema Design Phase
        1. Step 1: Gather Information
          1. Input
          2. Collate Management-Specific Information
          3. Ascertain Your Management Data Consumers
          4. Output
        2. Step 2: Define System Requirements, Rules, and Assertions
          1. Input
          2. Use Case Diagrams and Use Case Details
          3. Rules and Assertions
            1. Rules
            2. Assertions
          4. Output
        3. Step 3: Define Classes and Properties
          1. Input
          2. Name Your Schema
          3. MOF Qualifiers
          4. Define Candidate Classes
          5. Define Events
          6. Intrinsic Event Filter Example
          7. Define Statistical Classes
          8. Define Settings Classes
          9. Define Properties
          10. Class PO_PostOffice
          11. Discussion
          12. A Brief MOF Interlude
          13. MOF Language Tip
          14. Class PO_PostOfficeSettings
          15. Class PO_UserDetails
          16. Discussion
          17. Class PO_EmailAccount
          18. Discussion
          19. Class PO_Mailbag
          20. Discussion
        4. Class PO_MessageSettings
          1. Discussion
          2. Class PO_PostOfficeStats
          3. Output
        5. Step 4: Define Associations
          1. Input
          2. The Purpose of Associations
      13. Representing the PostOffice Schema in UML
        1. Output
      14. Summary
    8. 6. Method Design and Schema Class Positioning
      1. Properties vs. Methods
      2. Methods, Operations, and Functions
      3. Step 5: Define Methods
        1. Input
        2. Candidate Methods
          1. Retrieving Information from the Post Office Schema
            1. Scenario 1
            2. Scenario 2
          2. Method Design
          3. Assigning Methods to Host Classes
            1. Properties and Parameter Classes
        3. Method Arguments
          1. Advantages of Parameter Classes
        4. Method Overriding and Polymorphism
        5. The Post Office Schema Methods
          1. Why Define Preconditions and Postconditions?
        6. Method AddUser
          1. Host Class: PostOffice
        7. Method RemoveUser
          1. Host Class: PostOffice
        8. Method UnlockAccount
          1. Host Class: EmailAccount
        9. Method LockAccount
          1. Host Class: EmailAccount
        10. Method StopPostOffice
          1. Host class: PostOffice
        11. Method StartPostOffice
          1. Host Class: PostOffice
        12. Post Office Schema UML Diagram with Methods
        13. Output
      4. Step 6: Check Schema Design
        1. Input
        2. Rule Generation–Based UML Diagrams
        3. Final Considerations—Future Additions
      5. Final Step: Positioning Classes
      6. Step-by-Step CIMV2 Namespace Class Positioning
        1. Extending the CIMV2 Namespace
          1. Classes
          2. Associations
        2. Normalization
        3. CIMV2 Class Placement Objectives
      7. Putting Class Placement Theory into Practice
      8. Namespace and Schema Placement
      9. The Applications Namespace
        1. Limitations of Multinamespace Class Positioning
          1. Example 1. Executed in the CIMV2 Namespace
          2. Example 2. Executed in the PostOffice Namespace
          3. Example 3. Executed in the PostOffice Namespace
        2. Post Office Schema Namespace Positioning
        3. The Post Office Schema Class Positions
        4. Managed Object Format (MOF) Qualifiers and Flavors
      10. MOF Creation and Testing
      11. Implementing the Schema: WMI API Calls vs. MOF Code
      12. Multilanguage Support
      13. The Post Office Schema in MOF
        1. Brief MOF Syntax Reminder
      14. PO_PostOfficeHasSettings MOF File
      15. Testing
      16. Schema Deployment
      17. Summary
    9. 7. Developing Management Applications
      1. Getting Started
      2. Object Paths Explained
      3. Getting an Object
      4. Enumerating Objects
      5. Creating an Object
        1. First Point
        2. Second Point
        3. Third Point
        4. Example
      6. Updating Objects
      7. Deleting an Object
      8. Performing Queries
      9. Making Method Calls
      10. Manipulating Object Properties
      11. Manipulating Array Object Properties
      12. Accessing Objects from Object Properties
      13. Making Semisynchronous Calls
      14. Making Asynchronous Calls
      15. WMI Error Messages
      16. Overview of Events
      17. Intrinsic Events
      18. Extrinsic Events
      19. Timer Events
      20. How to Subscribe to Events
      21. Writing Applications to Receive Semisynchronous Events
      22. Writing Applications to Receive Asynchronous Events
      23. More on Security
      24. Classes that Require Specific Security Privileges
      25. Localized Namespaces
      26. Overview of High Performance Classes
      27. Writing Applications to Access High-Performance Data
      28. Access High-Performance Enumerated Data
      29. Summary
    10. 8. Developing .NET Management Applications
      1. Getting Started
      2. Getting a Management Object
      3. Enumerating Management Objects
      4. Creating a Management Object
        1. First Point
        2. Second Point
        3. Third Point
          1. Example
      5. Updating Management Objects
      6. Deleting a Management Object
      7. Performing Queries
      8. Making Method Calls
      9. Manipulating Management Object Properties
      10. Manipulating Array Object Properties
      11. Accessing Objects from Object Properties
      12. Making Asynchronous Calls
      13. Overview of Events
      14. Writing Applications to Receive Asynchronous Events
      15. Writing Applications to Receive Semisynchronous Events
      16. Managing Connections to WMI
      17. Summary
    11. 9. Developing MMC Snap-ins
      1. Snap-in Architecture
      2. Getting Started
      3. Snap-in Implementation Basics
      4. Let's Make a Snap-in
      5. Implementing IComponentData
      6. Implementing IComponent
      7. The Root Item and General Item Basics
      8. Adding Your Own Namespace Items
      9. Adding Your Own Columns
      10. Adding Your Own Result Items
      11. Setting Up and Handling Verbs
      12. Adding Your Own Menus
      13. Adding Your Own Toolbars
      14. Adding Your Own Property Pages
      15. Refocusing an Item's Property Sheet
      16. Adding Your Own Help
      17. Primary (Standalone) Snap-in Registration
      18. More on How ATL Delegates Tasks to an Item
      19. Renaming Items
      20. Drag and Drop
      21. Accessing Web Sites
      22. Displaying Custom Views
      23. Developing Extension Snap-ins
      24. Exchanging Information between Primary and Extension Snap-ins
      25. Extension Snap-in Registration
      26. Making MMC Snap-ins Theme Aware
      27. Summary
    12. 10. Developing WMI Scripts for Administrators
      1. Scripting, WMIC, and the CIM Studio
      2. Administration and the WMI CIM Studio
      3. Administration and the WMIC
      4. Administration and Scripting
      5. Guiding Principles
      6. Prerequisites
      7. Chapter Structure
      8. VBScript Boot Camp
      9. JavaScript vs. VBScript
      10. Setting Up Your System for Scripting
      11. Scripting and Administration
      12. What Is the Windows Scripting Host?
      13. Scripts
      14. Scripting vs. Compiled Languages
      15. The Windows Scripting Host
      16. Your First Script
      17. Indentation
      18. Annotation
      19. Variants, Variables, and Constants
      20. Use Meaningful Variable Names
      21. VBScript Functions
      22. The WSH Object Model
      23. Program Statements and Keywords
      24. The Option Explicit Statement
      25. Connecting to a Local or Remote Namespace
      26. Security Issues
      27. Deciding on the Level of Security Required
      28. Data Input
      29. Error Detection
      30. Error Logging (NT/2000/XP Only)
      31. WMI Scripting Data Retrieval
      32. Displaying Date and Time Values (XP Only)
      33. Retrieving Subsets of Instances
      34. WMI Data Modification Scripting Example
      35. Data Deletion Scripting Example
      36. Data Creation Scripting Example
      37. Association Traversal Using VBScript
      38. Executing Methods Using VBScript
      39. Summary
    13. 11. WMI Scripting and WMIC
      1. Identifying the Correct Course of Action
        1. Make a Note of the Problem Description
        2. Divide the Problem into Its Constituent Parts
        3. Decide Which Hardware or Software Components You Are Going to Manage
        4. Selecting a Namespace
        5. Which Tool?
        6. Decide Whether Your Script Should Run Locally or Remotely on the Target Machines
        7. Decide Whether Your Script Will Run Unattended or Attended
        8. Determine the Variables and Constants
          1. Candidate Constants
          2. Candidate Variables
        9. Determine the Sequence of Steps in the Task
      2. Script Deployment and Execution
        1. Local Execution and Storage
        2. Local Execution from a Shared Resource
        3. Remote Connection across a Network
        4. Remote Invocation of a Script (Available Only with Windows Script v5.6)
      3. Script Execution Methods
        1. Executing Scripts at Start Up
        2. Execute the Script Using the Windows Scheduler
        3. Event-driven Script Execution (Windows XP Only)
      4. Sending E-mail
      5. Setting Up Your System for Debugging and Testing
        1. Microsoft Windows Script Debugger (approx. 600k)
      6. Debugging Your Scripts
      7. Windows Management Instrumentation Command-line (WMIC)
      8. Using WMIC
      9. Interactive Mode
      10. Configuring WMIC
      11. Interacting with WMIC
      12. The WHERE Clause
      13. Verbs
      14. Adverbs
      15. Looping WMIC Commands
      16. Types of Output
      17. Aliases
      18. Creating or Modifying Aliases Using the CIM Studio
        1. Considerations
        2. Creating a Simple Alias from the WMIC Command Line
      19. Using WMIC in Noninteractive Mode
      20. Summary
    14. 12. Developing WMI Providers
      1. Where to Start
      2. Developing an Instance Provider
      3. Provider Registration
      4. Provider Initialization
      5. Enumerating Objects
      6. Getting an Object
      7. Deleting an Object
      8. Creating or Updating an Object
      9. Querying for Your Objects
      10. Instance Provider Registration
      11. Developing a Method Provider
      12. Executing Methods
      13. Method Provider Registration
      14. Developing an Event Provider
      15. Firing Events
      16. Event Provider Registration
      17. Developing an Event Consumer Provider
      18. Handling Event Notifications
      19. Permanent Event Consumer Provider Registration
      20. Developing a Property Provider
      21. Exposing Dynamic Properties
      22. Property Provider Registration
      23. Developing a Push Provider
      24. Pushing Data to the CIM Repository
      25. Push Provider Registration
      26. Security Considerations
      27. Summary
    15. 13. High-Performance Instrumentation
      1. Overview of Event Tracing
      2. Controlling Event Traces
        1. Starting a Kernel Event-Tracing Session
        2. Setting Up a Session's Configuration
        3. Querying the Session's Configuration and Statistics
        4. Stopping the Session
        5. Starting Event-Tracing Sessions
        6. Querying for Active Event-Tracing Sessions
        7. Querying for Registered Event-Tracing Providers
        8. Starting Private Event-Tracing Sessions
      3. Developing an Event-Tracing Provider
        1. Defining the Event Class Schema
        2. Registering an Application as an Event-Tracing Provider
        3. Developing the Provider's Control Call-Back Function
        4. Producing an Event Trace
        5. Producing a Hierarchical Event Trace
      4. Analyzing Event-Trace Log Files
        1. Processing an Event-Trace Log File
        2. The Event Call-Back Function
        3. The Buffer Call-Back Function
        4. The Consumer Event-Tracing APIs
      5. Monitoring Real-Time Event-Tracing Sessions
      6. Providing and Analyzing Lightweight Events
        1. Analyzing Lightweight Events
      7. Summary
    16. A. WMI Event SDK Tools
    17. B. WMI Server Explorer
      1. Manipulating Management Objects in the Server Explorer
      2. Subscribing for Event Notification in the Server Explorer
    18. Glossary
    19. Bibliography

    Product information

    • Title: Developing WMI Solutions: A Guide to Windows Management Instrumentation
    • Author(s):
    • Release date: November 2002
    • Publisher(s): Addison-Wesley Professional
    • ISBN: 9780201616132