logo资料库

Developing WMI Solutions A Guidue to Windows Management Instrume....pdf

第1页 / 共652页
第2页 / 共652页
第3页 / 共652页
第4页 / 共652页
第5页 / 共652页
第6页 / 共652页
第7页 / 共652页
第8页 / 共652页
资料共652页,剩余部分请下载后查看
Copyright
Preface
Who Is This Book for and What Is WMI?
How to Approach This Book and What You Will Learn
Chapter 1: Introduction
Chapter 2: Existing Management Frameworks
Chapter 3: Windows Management Instrumentation
Chapter 4: A Guided Tour of the Common Information Model Repository
Chapter 5: Developing Class Schemas
Chapter 6: Method Design and Schema Class Positioning
Chapter 7: Developing Management Applications
Chapter 8: Developing .NET Management Applications
Chapter 9: Developing MMC Snap-ins
Chapter 10: Developing WMI Scripts for Administrators
Chapter 11: WMI Scripting and WMIC
Chapter 12: Developing WMI Providers
Chapter 13: High-Performance Instrumentation
Where Can I Find the Sample Source Code and Scripts?
Glossary
Acknowledgments
Craig Tunstall
Gwyn Cole
Chapter 1. Introduction
Structure of the Book
Pedagogical Elements
Target Audience
Prerequisites
Terminology
Software Requirements
Operating System Requirements
Table 1.1. WMI-Supported Operating Systems Required
Hardware Requirements
Introducing WBEM
WBEM's Basic Objectives
Core Objectives
The Central Information Store
The Common Information Model
Object Orientation and CIM
Building an Information Model
Structure of the Centralized Repository
Figure 1.1. Inheritance and the difference between class and instance data
The Three-Tiered Model
Figure 1.2. The Common Information Model has three tiers
Acronyms and Terminology
Standards Bodies
Motivation
De Facto and de Jure Standards
The Distributed Management Task Force (DMTF)
Figure 1.3. The DMTF working groups
Figure 1.4. Key stages in the evolution of the WBEM
The World Wide Web Consortium (W3C)
Web-Based Enterprise Management (WBEM)
Windows Management Instrumentation (WMI)
Common Information Model (CIM)
Common Information Model (CIM) Repository
Managed Object Format (MOF)
Simple Network Management Protocol (SNMP)
Common Management Information Services (CMIS)
Common Management Information Protocol (CMIP)
Desktop Management Interface (DMI)
eXtensible Markup Language (XML)
Hypertext Transfer Protocol (HTTP)
Extended Schemas
WMI Scripting
Summary
Ten Fast Facts: Web-Based Enterprise Management
Chapter 2. Existing Management Frameworks
The Need for a Universal Management Model
Figure 2.1. A typical network management scenario
The Simple Network Management Protocol
A Simple Solution to a Complex Problem
The SNMP Network Management Station
Figure 2.2. An SNMP-managed network
Relevant SNMP Standards
Figure 2.3. The components and relationships between elements of SNMP
Figure 2.4. An SNMP network management station (NMS) and SNMP agent interacting
Structure of an SNMP Message
Figure 2.5. The basic structure of an SNMP message over TCP/IP
Communities
Figure 2.6. Security verification in SNMP 1 and SNMP 2c using communities
Event Notification: SNMP Traps and Informs
The Management Information Base
Figure 2.7. A partial MIB tree hierarchy
SNMP Security
Modus Operandi
Table 2.1. SNMP Operations
Figure 2.8. The GetRequest operation
Figure 2.9. The SetRequest operation
Figure 2.10. The SNMP trap
Figure 2.11. A simplified version of the functional block diagram (excluding features unique to DMI 2.0s)
Advantages of the SNMP Protocol
Disadvantages of the SNMP Protocol
The Desktop Management Interface
The DMI Information Model: The Management Store
Figure 2.12. Attribute presentation within the DMI Data Model
Figure 2.13 An excerpt from a MIF file to describe the attribute Group:Disk
Policy
Notification of Events
DMI Security
MIF Database Security
Management Interface Security
Component Interface Security
Security Indications
Advantages of the DMI
Disadvantages of the DMI
Summary
Common Elements for Management Frameworks
Figure 2.14. A two-tiered approach to data instrumentation
Figure 2.15. A three-tiered approach to data instrumentation
The Need for a Unified Management Framework
Ten Fast Facts: SNMP and DMI
Chapter 3. Windows Management Instrumentation
The Standard WBEM Components
Installing WMI
Installation Files
Core (WMICORE.EXE) (approximately 6.5 Mb)
WMI SDK (WMISDK.EXE) (approximately 12Mb)
Configuring Windows 98 for WMI
Table 3.1. AutoStartWin9x Registry Value Options
Optional Setting
Core Components of WMI
winMgmt.exe: The Windows Management Service
Figure 3.1. The command-line options for the Winmgmt executable
mofcomp.exe: The Microsoft MOF Compiler
Table 3.2. mofcomp Command-Line Options
Figure 3.2. The WMI Control snap-in for Windows 2000/WinXP/.NET
The WMI Control
Windows Management Instrumentation Tester
Figure 3.3. The Windows Management Instrumentation Tester
Automatic MOF Registration
WMI Log Files
WMI CIM Repository
Windows Management Instrumentation
The Basic Framework of WMI
Figure 3.4. An overview of the WMI architecture
WMI Management Applications
Direct Access
Indirect Access
Providers
Table 3.3. Windows Operating System WMI Providers
Types of Providers
Event Providers
Figure 3.5. The simplified event consumer/event provider model
Data Providers
Table 3.4. Types of WMI Providers
Table 3.5. WMI Provider Classifications
Event Handling
Intrinsic Events
Extrinsic Events
Timer Events
Event Consumer
Temporary Consumers
Permanent Consumers
WMI Security
Authentication
WMI Permission Assignment Using WMI Control
Figure 3.6. The WMI Control Security tab displaying the available namespaces
Figure 3.7. Setting the security options for group or user names
Table 3.6. WMI Namespace Permission Types
WMI Security on Windows 9x
The WMI Query Language
Figure 3.8. The Windows Management Instrumentation Tester main dialog
Figure 3.9. The Connect dialog
Figure 3.10. The Query dialog
Data Queries
Table 3.7. ASSOCIATORS OF Statement Keywords
Table 3.8. REFERENCES OF Statement Keywords
Event Queries
Schema Queries
Summary
Ten Fast Facts: Windows Management Instrumentation
Chapter 4. A Guided Tour of the Common Information Model Repository
Metadata
Table 4.1. Metadata Examples
Dynamic and Static Data
Dynamic Data and the CIM Repository
Figure 4.1. Example topology without any mechanism to supply dynamic data
Figure 4.2. Example topology in which product supplies WMI with dynamic data
The Common Information Model
Figure 4.3. The three layers of CIM
The Core Model
The Common Model
Systems Model
Networks Model
Devices Model
Physical Model
Applications Model
Event Model
Policy Model
Support Model
User Model
Metrics Model
Interop Model
The Extended Schemas
Namespaces
Using the CIMV2 Namespace
Table 4.2. Likely Management Object Locations
WMI Namespaces and the CIM repository
Figure 4.4. Example of namespaces found in a Windows XP installation
Table 4.3. Windows XP Namespaces
Defining and Using Your Own Namespace
Figure 4.5. Namespaces and the CIM repository
Namespaces and Schemas
Using Existing Schemas
Subclassing and Instantiating Existing Classes in the CIMV2 Namespace
Modifying Existing Classes
Managed Object Format
MOF Class Declaration
Figure 4.6 A MOF class declaration
Qualifiers
Figure 4.7 Example qualifiers
Flavors
Figure 4.8 Example flavors
Custom Qualifiers
User-Defined Qualifiers
Intrinsic Data Types
Table 4.4. Intrinsic Data Types
Instance Creation
Figure 4.9 Creating an instance of MOF
Aliasing
Figure 4.10 Using an alias in MOF
A Compileable MOF File
Figure 4.11 A compilable MOF (part 1 of 2)
Figure 4.12. The CIM repository with the new namespace, Example1
Figure 4.13 A compileable MOF (part 2 of 3)
Figure 4.14 A compileable MOF (Part 3 of 3)
ActiveX Components
Let the Tour Begin!
Figure 4.15. Browsing and attaching to a namespace
Figure 4.16. The WMI CIM Studio
Figure 4.17. Class explorer functions
Figure 4.18. Class viewer functions
The Class Explorer Explained
Figure 4.19. CIM Studio icon definitions
Associations
Figure 4.20 An example association
Key Propagation
Figure 4.21 Example of key propagation
Figure 4.22 Instance of an association
Namespaces and Associations
Figure 4.23. The cross namespace associations rule
Figure 4.24. CIM Studio property types
System Properties
Table 4.5. WMI System Properties
Object and Property Qualifiers
Figure 4.25. The Object qualifiers window for class MySchema_CDROM
Table 4.6. Object Qualifiers
Table 4.7. Property Qualifiers
Figure 4.26. The Property qualifiers dialog window
CIM Studio Functions
Help for a Class
Figure 4.27 MOF for storage class
Figure 4.28. The Help dialog for class MySchema_Storage
Browse for a Namespace
Search for a Class
Figure 4.29. The Search for Class dialog
Figure 4.30. Search facility automatically goes to the class you select from the search results
Figure 4.31. The Associations view
Instance Enumeration
Change the View (System Properties and Inherited Properties)
Figure 4.32. The Select Properties dialog
WQL Queries Tool
Figure 4.33. The Query dialog box allows you to create, save, and execute WQL queries
Add a Class
Figure 4.34. The Add Class dialog
Create an Association
Delete a Class or Association
Delete a Property
Add an Instance
Delete an Instance
Places of Interest within the CIM repository
The Provider Classes
Table 4.8. Provider System Classes
The Namespace Classes
Figure 4.35. Enumerating the __NAMESPACE class
Create a Namespace
Delete a Namespace
Tutorial: Creating a Namespace and Adding Classes, Properties, and an Association
Figure 4.36. Adding a key property
The Wizards
Figure 4.37. The wizards available in the WMI CIM Studio
The MOF Generator
The MOF Compiler
The Provider Code Generator
Summary
Ten Fast Facts: CIM Repository
Chapter 5. Developing Class Schemas
Schema Design and System Manageability
Figure 5.1. WMI product instrumentation life cycle overview
Case Study: Client/Server E-mail Package
Figure 5.2. Client Server e-mail topology
Basic Functionality
System Requirements for Post Office E-mail
The Unified Modeling Language
Further Reading in UML
Learning the CIM Schema and Win32 Extended Schemas
Psychological Requirements
Schema Design Timescales
Software Application Life Cycle
Figure 5.3. The software application life cycle
The Windows Installer and WMI
The Role of WMI with Standard Software Applications and Management Software Applications
Schema Design by Teams vs. by Single Developers
When Should I Commit My Design to UML?
Can I Design a Schema without UML?
The Unified Modeling Language in Schema Design
A Brief Introduction to UML Object Modeling
Figure 5.4. Class notation in UML
Figure 5.5. Default UML compartment names
Figure 5.6. Class notation with properties and methods suppressed
Figure 5.7. Class notation with properties, types, default values, and methods shown
Inheritance Notation
Figure 5.8. Inheritance in UML
Association Notation
Figure 5.9. Associations in UML
Table 5.1. Relationship Cardinality
Figure 5.10. Associations in UML
Aggregate Associations
Figure 5.11. Aggregate associations in UML
Figure 5.12. Instance association of aggregate relationship
Figure 5.13 Aggregate relationship association class
Interpreting the Common Model in UML
Figure 5.14. The Common Model from the CIM schema
The Schema Design Road Map
Figure 5.15. The Schema Design Road Map
Basic Rules for Schema Design
Telephone Operator Example
WMI Topology Design
First Approach
Figure 5.16. A centralized approach to instrumenting the E-mail package
Table 5.2. Pros and Cons of the First Approach
Second Approach
Figure 5.17. A decentralized approach to instrumenting the e-mail package in WMI
Table 5.3. Pros and Cons of the Second Approach
Schema Design Phase
Step 1: Gather Information
Input
Collate Management-Specific Information
Ascertain Your Management Data Consumers
Output
Step 2: Define System Requirements, Rules, and Assertions
Input
Use Case Diagrams and Use Case Details
Figure 5.18. Use Case diagram for the Post Office
Table 5.4. Post Office Management Functions
Figure 5.19 Use Case details for management function Shutdown Post Office
Rules and Assertions
Rules
Table 5.5. Post Office Rules
Assertions
Table 5.6. Post Office Assertions
Output
Step 3: Define Classes and Properties
Input
Name Your Schema
MOF Qualifiers
Define Candidate Classes
Table 5.7. Candidate Classes for the Post Office Schema
Define Events
Table 5.8. Intrinsic Event Classifications
Table 5.9. Intrinsic Event Classifications
Intrinsic Event Filter Example
Figure 5.20 Event filter for locked accounts
Figure 5.21 Event filter for large mailbox accounts
Define Statistical Classes
Table 5.10. Candidate Statistical Classes for the Post Office
Define Settings Classes
Table 5.11. Candidate Settings Classes for the Post Office
Define Properties
Table 5.12. Post Office Classes with Candidate Properties
Class PO_PostOffice
Table 5.13. Class PO_PostOffice Properties
Discussion
A Brief MOF Interlude
MOF Language Tip
Class PO_PostOfficeSettings
Class PO_UserDetails
Table 5.14. Class PO_PostOfficeSettings Properties
Table 5.15. Class PO_UserDetails Properties
Discussion
Class PO_EmailAccount
Table 5.16. Class PO_EmailAccount Properties
Discussion
Table 5.17. AccountStatus Property Values
Class PO_Mailbag
Table 5.18. Class PO_Mailbag Properties
Discussion
Class PO_MessageSettings
Table 5.19. Class PO_MessageSettings Properties
Discussion
Class PO_PostOfficeStats
Table 5.20. Class PO_PostOfficeStats Properties
Output
Step 4: Define Associations
Input
The Purpose of Associations
Table 5.21. Candidate Associationsa
Table 5.22. Association Cardinality
Table 5.23. Association Endpoints
Representing the PostOffice Schema in UML
Figure 5.22. A UML object model of the Post Office schema system showing the classes and associations. Note that we position our Post Office schema classes in the next chapter.
Output
Summary
Ten Starting Schema Design Tips
Chapter 6. Method Design and Schema Class Positioning
Properties vs. Methods
Methods, Operations, and Functions
Table 6.1. Difference between Operations and Functions
Step 5: Define Methods
Input
Candidate Methods
Table 6.2. Candidate Post Office Methods
Retrieving Information from the Post Office Schema
Scenario 1
Scenario 2
Method Design
Assigning Methods to Host Classes
Table 6.3. Post Office Methods and Associated Host Class
Properties and Parameter Classes
Method Arguments
Figure 6.1 Method arguments specified in method signature
Advantages of Parameter Classes
Figure 6.2 Method arguments specified through parameter class
Figure 6.3 Final method signature
Method Overriding and Polymorphism
The Post Office Schema Methods
Why Define Preconditions and Postconditions?
Method AddUser
Host Class: PostOffice
Figure 6.4 Method parameter class for new users
Table 6.4. AddUser Method Specification
Method RemoveUser
Host Class: PostOffice
Table 6.5. RemoveUser Method Specification
Method UnlockAccount
Host Class: EmailAccount
Table 6.6. UnlockAccount Method Specification
Method LockAccount
Host Class: EmailAccount
Table 6.7. LockAccount Method Specification
Method StopPostOffice
Host class: PostOffice
Table 6.8. StopPostOffice Method Specification
Method StartPostOffice
Host Class: PostOffice
Table 6.9. StartPostOffice Method Specification
Post Office Schema UML Diagram with Methods
Figure 6.5. The Post Office UML object model (including methods and parameter class)
Output
Step 6: Check Schema Design
Input
Table 6.10. Post Office Rules
Table 6.11. Post Office Assertions
Rule Generation–Based UML Diagrams
Final Considerations—Future Additions
Final Step: Positioning Classes
Table 6.12. Schema Positioning Stages
Step-by-Step CIMV2 Namespace Class Positioning
Extending the CIMV2 Namespace
Table 6.13. Classes That Can Be Subclassed
Table 6.14. Associations That Can Be Subclassed
Classes
Associations
Normalization
CIMV2 Class Placement Objectives
Putting Class Placement Theory into Practice
Table 6.15. CIM Models
Figure 6.6. The help facility in WMI CIM Studio
Table 6.16. Post Office Class Positioning in the CIM Namespace
Namespace and Schema Placement
The Applications Namespace
Table 6.17. Advantages and Disadvantages of Namespace Positioning
Limitations of Multinamespace Class Positioning
Figure 6.7. An arrangement of classes from the Post Office schema
Example 1. Executed in the CIMV2 Namespace
Example 2. Executed in the PostOffice Namespace
Example 3. Executed in the PostOffice Namespace
Post Office Schema Namespace Positioning
The Post Office Schema Class Positions
Figure 6.8. Post Office schema settings classes
Figure 6.9. Post Office schema statistical classes
Figure 6.10. Post Office schema method parameter classes
Figure 6.11. Post Office schema dependency classes
Figure 6.12. Post Office schema managed element classes
Figure 6.13. Post Office schema element classes
Managed Object Format (MOF) Qualifiers and Flavors
MOF Creation and Testing
Implementing the Schema: WMI API Calls vs. MOF Code
Multilanguage Support
Figure 6.14 Example of the amendment qualifier
Figure 6.15 Example of the amended qualifier
Figure 6.16 Example of the DisplayName qualifier
Figure 6.17 Example of the amendment MOF compiler directive
The Post Office Schema in MOF
Brief MOF Syntax Reminder
PO_PostOfficeHasSettings MOF File
Figure 6.18. The root/CIMV2/Applications/PostOffice namespace
Testing
Schema Deployment
Summary
Schema Design and Positioning Q & A
Chapter 7. Developing Management Applications
Getting Started
Object Paths Explained
Getting an Object
Enumerating Objects
Figure 7.1. Win32_Account class hierarchy
Creating an Object
First Point
Second Point
Third Point
Example
Updating Objects
Deleting an Object
Performing Queries
Making Method Calls
Manipulating Object Properties
Table 7.1. CIM Data Type to Variant Mappings
Table 7.2. DATETIME Field Descriptions for Absolute Date/Time
Table 7.3. DATETIME Field Descriptions for Interval Times
Manipulating Array Object Properties
Accessing Objects from Object Properties
Making Semisynchronous Calls
Making Asynchronous Calls
WMI Error Messages
Overview of Events
Figure 7.2. WMI event interaction
Intrinsic Events
Table 7.4. Intrinsic Event Classes
Figure 7.3. WMI event classes
Extrinsic Events
Figure 7.4. WMI extrinsic event classes
Timer Events
Figure 7.5. WMI timer instruction classes
How to Subscribe to Events
Writing Applications to Receive Semisynchronous Events
Writing Applications to Receive Asynchronous Events
Figure 7.6. DCOM client callback problem
Figure 7.7. DCOM client callback solution
More on Security
Classes that Require Specific Security Privileges
Localized Namespaces
Figure 7.8. Example WMI namespace structure
Overview of High Performance Classes
Writing Applications to Access High-Performance Data
Access High-Performance Enumerated Data
Summary
Ten Fast Facts: Developing C++/COM Management Applications:
Chapter 8. Developing .NET Management Applications
Getting Started
Figure 8.1. Major .NET Framework management classes
Getting a Management Object
Enumerating Management Objects
Creating a Management Object
First Point
Second Point
Third Point
Example
Updating Management Objects
Deleting a Management Object
Performing Queries
Making Method Calls
Manipulating Management Object Properties
Table 8.1. CIM Data Type to C# Mappings
Table 8.2. DATETIME Field Descriptions for Absolute Date/Time
Table 8.3. DATETIME Field Descriptions for Interval Times
Manipulating Array Object Properties
Accessing Objects from Object Properties
Making Asynchronous Calls
Overview of Events
Writing Applications to Receive Asynchronous Events
Writing Applications to Receive Semisynchronous Events
Managing Connections to WMI
Summary
Ten Fast Facts: Developing .NET Management Applications
Chapter 9. Developing MMC Snap-ins
Figure 9.1. The Microsoft Management Console
Snap-in Architecture
Figure 9.2. MMC item unique identifiers
Figure 9.3. MMC's installed snap-ins list
Getting Started
Figure 9.4. MMC interfaces and snap-in components
Table 9.1. MMC Console Interfaces
Table 9.2. MMC Snap-in Interfaces
Figure 9.5. MMC snap-in objects
Snap-in Implementation Basics
Figure 9.6. MMC snap-in ATL objects
Table 9.3. MMC ATL Snap-in Component C++ Templates
Table 9.4. MMC ATL Snap-in Framework C++ Templates
Let's Make a Snap-in
Figure 9.7. Windows 2000 Services snap-in
Figure 9.8. Service item's menu
Figure 9.9. Service item's toolbar
Implementing IComponentData
Implementing IComponent
The Root Item and General Item Basics
Figure 9.10. Snap-in with root item
Adding Your Own Namespace Items
Figure 9.11. Snap-in with Service item
Adding Your Own Columns
Figure 9.12. Snap-in with columns
Adding Your Own Result Items
Figure 9.13. Snap-in with result pane items
Setting Up and Handling Verbs
Table 9.5. Common Snap-in Verbs
Figure 9.14. Snap-in with refresh verb enabled
Adding Your Own Menus
Figure 9.15. Snap-in menu structure
Figure 9.16. Snap-in menu resource structure
Figure 9.17. Snap-in item with custom menu
Adding Your Own Toolbars
Figure 9.18. Snap-in toolbar resource
Figure 9.19. Snap-in item with toolbar
Adding Your Own Property Pages
Figure 9.20. Snap-in item with properties verb enabled
Figure 9.21. Snap-in item's property sheet
Refocusing an Item's Property Sheet
Adding Your Own Help
Primary (Standalone) Snap-in Registration
More on How ATL Delegates Tasks to an Item
Renaming Items
Figure 9.22. Renaming snap-in item
Drag and Drop
Figure 9.23. Dragging snap-in items from result pane to scope pane item
Accessing Web Sites
Figure 9.24. Snap-in item displaying a Web page
Displaying Custom Views
Figure 9.25. Snap-in item hosting an ActiveX control
Developing Extension Snap-ins
Figure 9.26. Snap-in extension mechanism
Figure 9.27. Snap-in extension item binding
Figure 9.28. Extension snap-in adding a menu item
Figure 9.29. Extension snap-in example action
Exchanging Information between Primary and Extension Snap-ins
Figure 9.30. Extension snap-in adding a menu item with context information
Extension Snap-in Registration
Making MMC Snap-ins Theme Aware
Figure 9.31. MMC snap-in: Not theme aware
Figure 9.32. MMC snap-in: Theme aware
Summary
Ten Fast Facts: Developing MMC Snap-ins
Chapter 10. Developing WMI Scripts for Administrators
Scripting, WMIC, and the CIM Studio
Administration and the WMI CIM Studio
Administration and the WMIC
Administration and Scripting
Guiding Principles
Prerequisites
Chapter Structure
VBScript Boot Camp
JavaScript vs. VBScript
Setting Up Your System for Scripting
Scripting and Administration
Table 10.1. Matching Common Administrative Tasks to WMI Equivalent
What Is the Windows Scripting Host?
Scripts
Scripting vs. Compiled Languages
BEST PRACTICE! Script Signing
The Windows Scripting Host
Your First Script
Figure 10.1. First script
Figure 10.2. Results of running example1.vbs
Figure 10.4. The result of calling the InputBox function
Figure 10.3 GUI output using script
Indentation
BEST PRACTICE! Code Indentation
Annotation
BEST PRACTICE! Code Annotation
Variants, Variables, and Constants
Use Meaningful Variable Names
BEST PRACTICE! Variable Naming
VBScript Functions
The WSH Object Model
Program Statements and Keywords
Table 10.2. VBScript Keywords
The Option Explicit Statement
BEST PRACTICE! Variable Declaration
Connecting to a Local or Remote Namespace
Figure 10.5 Scripts That interact with the GUI Note: Because we haven't discussed error checking yet we shall assume that the GetObject call always returns successfully (that is, attaches to a namespace).
Figure 10.6. The WMI Control Advanced tab can be used to set the default namespace on a machine
Table 10.3. Security Flags for ConnectServer
BEST PRACTICE! Using a password and username to attach to a namespace
BEST PRACTICE! Retrieving locale-specific information
Security Issues
Table 10.4. Security Impersonation Levels
Table 10.5. Security Authentication Levels
Table 10.6. Security Privilege Constants[*]
Deciding on the Level of Security Required
BEST PRACTICE! Connecting to a namespace
Data Input
Figure 10.7 Input through the command line Note: If you do not supply the correct number of arguments in this example, then the script will fail.
Figure 10.8 Input through the GUI
Error Detection
Figure 10.9 Calling subroutines
Figure 10.11. The Standard Error and WMI Extended Error Information dialog boxes
Table 10.7. VBScript Constants
Figure 10.10 Subroutines to display errors
Table 10.8. MsgBox Appearance Constants
Table 10.9. MsgBox Modal Constants
BEST PRACTICE! User/Script Interaction
Error Logging (NT/2000/XP Only)
BEST PRACTICE! Tracking Unattended Script Behavior
Table 10.10. Event Logging Types
Figure 10.13. Event generated by LogWMIError
WMI Scripting Data Retrieval
Figure 10.12 Subroutines to record errors in the Windows event log
BEST PRACTICE! Using InstancesOf
Figure 10.14 Retrieving the network log-in name and date from WMI
Figure 10.15. Example of a date value without formatting
Displaying Date and Time Values (XP Only)
Figure 10.16. Example of date formatting using SWBemDateTime
Retrieving Subsets of Instances
Figure 10.17 Uses a WQL query to get the default printer
Figure 10.18 Uses a WQL query to list Windows services not started
Figure 10.19 A WQL query to get the alerter Windows services
BEST PRACTICE! Use the Get Method
BEST PRACTICE! Use Semisynchronous Calls to ExecQuery
WMI Data Modification Scripting Example
Figure 10.20 Example script that enables disabled user accounts
Figure 10.21. A MsgBox with the vbYesNo, vbSystemModal, and vbQuestion flags set
Table 10.11. MsgBox Button Constants
Data Deletion Scripting Example
Figure 10.22. Using MsgBox to elicit a response from the user
Data Creation Scripting Example
Figure 10.23 Retrieves all the currently installed printers and offers an option to delete
Association Traversal Using VBScript
Figure 10.24 Creating a printer configuration
Executing Methods Using VBScript
Figure 10.25 Find printers attached to a parallel port
Summary
Figure 10.26 Finds the default printer and prints the test page
Ten Fast Facts: Summary of VBScript Boot Camp
Chapter 11. WMI Scripting and WMIC
Identifying the Correct Course of Action
Make a Note of the Problem Description
Divide the Problem into Its Constituent Parts
Decide Which Hardware or Software Components You Are Going to Manage
Selecting a Namespace
Figure 11.1. The Search dialog of the WMI CIM Studio
BEST PRACTICE! Properties vs. Methods
Which Tool?
Table 11.1. Administration Tools
Decide Whether Your Script Should Run Locally or Remotely on the Target Machines
Decide Whether Your Script Will Run Unattended or Attended
Table 11.2. Attended and Unattended Inputs and Outputs
Determine the Variables and Constants
Candidate Constants
Candidate Variables
Determine the Sequence of Steps in the Task
Script Deployment and Execution
Local Execution and Storage
Figure 11.2. The script is stored and runs locally
Local Execution from a Shared Resource
Figure 11.3. The script is stored centrally on a shared drive and runs locally
Remote Connection across a Network
Figure 11.4. The script is stored locally and attaches across the network to the remote namespace
Remote Invocation of a Script (Available Only with Windows Script v5.6)
Figure 11.5. The script is stored locally, copied across the network, and executed as a process in the remote machine
Figure 11.6 Running a script on a remote machine
Script Execution Methods
Executing Scripts at Start Up
Execute the Script Using the Windows Scheduler
Figure 11.7. The Windows task scheduler
Event-driven Script Execution (Windows XP Only)
Sending E-mail
Figure 11.8 Sends an e-mail of all Windows services
Setting Up Your System for Debugging and Testing
Microsoft Windows Script Debugger (approx. 600k)
Figure 11.9. Use Notepad to create a new file called scriptdebug.reg
Figure 11.10 Registry changes to enable script debugging
Figure 11.11. The two new settings available on the Context menu for .vbs files
Debugging Your Scripts
Figure 11.12. The Windows Script debugger main screen
Figure 11.13. Setting breakpoints in the debugger using F9
Figure 11.14. The command window can retrieve the value of variables
Figure 11.15. The command window also can be used to set the value of variables
Windows Management Instrumentation Command-line (WMIC)
Using WMIC
Interactive Mode
Figure 11.16. The WMIC command prompt
Figure 11.17. The /? sequence retrieves all available switches, Aliases, and commands
Configuring WMIC
Figure 11.18. WMIC configuration
Interacting with WMIC
Figure 11.19. Usage information on an Alias
The WHERE Clause
Table 11.3. Comparison Operators
Verbs
Table 11.4. List of WMIC Verbs
Adverbs
Looping WMIC Commands
Types of Output
Table 11.5. Supplied XSL Files for Outputting WMIC Results
Aliases
Figure 11.20 The basic structure of an Alias in MOF format stored in the root\cli namespace by default
Figure 11.21. The MSFT_CliAlias class in the root\Cli namespace
Figure 11.22. The NIC Alias, up close and personal
Figure 11.23. The Embedded Object dialog for class MSFT_CliConnection
Figure 11.24. An array of objects associated with the Formats property
Figure 11.25. Properties of the STATUS format option
Figure 11.26. The NIC Alias in action
Creating or Modifying Aliases Using the CIM Studio
Considerations
Creating a Simple Alias from the WMIC Command Line
Using WMIC in Noninteractive Mode
Figure 11.27. WMIC can format the output in a variety of predesigned styles
BEST PRACTICE! Usernames and Passwords
Summary
Ten Fast Facts: WMIC Tips
Chapter 12. Developing WMI Providers
Figure 12.1. WMI client/provider architecture
Where to Start
Developing an Instance Provider
Figure 12.2. WMI instance provider class schema
Figure 12.3. WMI instance provider component
Provider Registration
Figure 12.4. WMI provider registration class hierarchy
Provider Initialization
Enumerating Objects
Figure 12.5. Fruit basket registry structure
Getting an Object
Deleting an Object
Creating or Updating an Object
Querying for Your Objects
Figure 12.6. Query processing from provider to client
Instance Provider Registration
Developing a Method Provider
Figure 12.7. WMI method provider component
Executing Methods
Method Provider Registration
Developing an Event Provider
Figure 12.8. WMI event provider component
Firing Events
Event Provider Registration
Developing an Event Consumer Provider
Handling Event Notifications
Figure 12.10. WMI event consumer provider classes
Figure 12.9. WMI event consumer provider component
Permanent Event Consumer Provider Registration
Developing a Property Provider
Figure 12.11. WMI property provider component
Exposing Dynamic Properties
Property Provider Registration
Developing a Push Provider
Figure 12.12. WMI push provider component
Pushing Data to the CIM Repository
Push Provider Registration
Security Considerations
Figure 12.13. Remote access boundaries between clients and providers
Summary
Ten Fast Facts: Developing WMI Providers
Chapter 13. High-Performance Instrumentation
Overview of Event Tracing
Figure 13.1. Event-tracing architecture
Controlling Event Traces
Starting a Kernel Event-Tracing Session
Setting Up a Session's Configuration
Figure 13.2. EVENT_TRACE_PROPERTIES structure
Table 13.1. LogFileMode Flags
Table 13.2. EnableFlags Flags
Querying the Session's Configuration and Statistics
Table 13.3. ControlCode Flags
Stopping the Session
Starting Event-Tracing Sessions
Querying for Active Event-Tracing Sessions
Querying for Registered Event-Tracing Providers
Table 13.4. Published Event-Tracing Providers
Starting Private Event-Tracing Sessions
Figure 13.3. Starting a kernel or normal session
Figure 13.4. Starting a private session
Developing an Event-Tracing Provider
Figure 13.5. Lift Simulator event trace
Defining the Event Class Schema
Registering an Application as an Event-Tracing Provider
Developing the Provider's Control Call-Back Function
Producing an Event Trace
Figure 13.6. Event-trace schema for Lift Simulator
Table 13.5. Standard Event Types
Table 13.6. FieldTypeFlags Flags
Table 13.7. Flags Bit-Mask Values
Producing a Hierarchical Event Trace
Figure 13.7. Flat versus hierarchical event trace
Analyzing Event-Trace Log Files
Processing an Event-Trace Log File
The Event Call-Back Function
Figure 13.8. Print spooler's event-trace schema
Figure 13.9. Processing single versus multiple event-tracing log files
The Buffer Call-Back Function
The Consumer Event-Tracing APIs
Monitoring Real-Time Event-Tracing Sessions
Providing and Analyzing Lightweight Events
Table 13.8. MessageFlags Flags
Analyzing Lightweight Events
Figure 13.10. Interpreting TraceMessage events
Summary
Ten Fast Facts: High-Performance Instrumentation
Appendix A. WMI Event SDK Tools
Figure A.1. WMI Event Viewer
Figure A.2. WMI Event Registration
Figure A.3. Creating a new event query
Figure A.4. Entering configuration for new event query
Figure A.5. Creating new event consumer
Figure A.6. Entering configuration for new event consumer
Figure A.12. WMI Event Viewer displaying events from multiple consumers
Figure A.7. Associating an event query to an event consumer
Figure A.8. WMI Event Viewer displaying newly received event
Figure A.9. Creating new time instruction
Figure A.10. Entering configuration for new interval timer instruction
Figure A.11. Associating a timer event query to an event consumer
Figure A.13. Viewing an event in the WMI Event Viewer
Figure A.14. Viewing TargetInstance property
Appendix B. WMI Server Explorer
Figure B.1. The Visual Studio .NET Server Explorer
Manipulating Management Objects in the Server Explorer
Figure B.2. Add Classes dialog
Figure B.3. The newly added management classes
Figure B.4. The WMI Object Browser showing the fruit basket objects
Figure B.5. The WMI Server Explorer showing the fruit basket objects
Figure B.6. The WMI Server Explorer properties window
Figure B.7. The Fruit class menu
Figure B.8. The AddFruitToBasket method dialog
Subscribing for Event Notification in the Server Explorer
Figure B.9. The Build Management Event Query dialog
Figure B.10. The available classes list
Figure B.11. The Advanced Query Options dialog
Figure B.12. Specifying the MediaLoaded=true condition
Figure B.13. The CD-ROM event query subscription
Figure B.14. The Visual Studio .NET output window
Glossary
Bibliography
"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.
COPYRIGHT ..................................................................................................................15 PREFACE...........................................................................................................................17 Who Is This Book for and What Is WMI?.........................................17 How to Approach This Book and What You Will Learn .....18 Acknowledgments...................................................................................................21 CHAPTER 1. INTRODUCTION................................................................22 Structure of the Book ...........................................................................................23 Pedagogical Elements........................................................................................24 Target Audience........................................................................................................24 Prerequisites.................................................................................................................25 Terminology...................................................................................................................25 Software Requirements.....................................................................................25 Operating System Requirements.............................................................26 Hardware Requirements...................................................................................26 Introducing WBEM..................................................................................................27 WBEM's Basic Objectives...............................................................................27 Core Objectives.........................................................................................................27 The Central Information Store.....................................................................27 The Common Information Model..............................................................28 Object Orientation and CIM...........................................................................28 Building an Information Model ....................................................................28 Structure of the Centralized Repository ............................................29 The Three-Tiered Model...................................................................................30 Acronyms and Terminology...........................................................................31 Standards Bodies ....................................................................................................31 Motivation ........................................................................................................................32 De Facto and de Jure Standards.............................................................32 The Distributed Management Task Force (DMTF) ................33 The World Wide Web Consortium (W3C) .......................................35 Web-Based Enterprise Management (WBEM) ..........................36 Windows Management Instrumentation (WMI)..........................36 Common Information Model (CIM).........................................................36
Common Information Model (CIM) Repository...........................36 Managed Object Format (MOF)................................................................37 Simple Network Management Protocol (SNMP) ......................37 Common Management Information Services (CMIS)..........37 Common Management Information Protocol (CMIP)...........37 Desktop Management Interface (DMI) ...............................................38 eXtensible Markup Language (XML)....................................................38 Hypertext Transfer Protocol (HTTP).....................................................38 Extended Schemas................................................................................................39 WMI Scripting ..............................................................................................................39 Summary..........................................................................................................................39 TEN FAST FACTS: WEB-BASED ENTERPRISE MANAGEMENT ........................................................................................................40 CHAPTER 2. EXISTING MANAGEMENT FRAMEWORKS..........................................................................................................41 The Need for a Universal Management Model ..........................42 The Simple Network Management Protocol .................................44 A Simple Solution to a Complex Problem .......................................44 The SNMP Network Management Station......................................45 Relevant SNMP Standards............................................................................47 Structure of an SNMP Message ...............................................................49 Communities.................................................................................................................49 Event Notification: SNMP Traps and Informs..............................51 The Management Information Base......................................................52 SNMP Security...........................................................................................................55 Modus Operandi .......................................................................................................56 Advantages of the SNMP Protocol ........................................................58 Disadvantages of the SNMP Protocol.................................................58 The Desktop Management Interface....................................................59 The DMI Information Model: The Management Store.........61 Policy....................................................................................................................................62 Notification of Events ...........................................................................................62 DMI Security .................................................................................................................62
MIF Database Security.......................................................................................63 Management Interface Security ................................................................63 Component Interface Security ....................................................................64 Security Indications................................................................................................64 Advantages of the DMI.......................................................................................64 Disadvantages of the DMI...............................................................................64 Summary..........................................................................................................................65 TEN FAST FACTS: SNMP AND DMI .......................................67 CHAPTER 3. WINDOWS MANAGEMENT INSTRUMENTATION...........................................................................................68 The Standard WBEM Components .......................................................69 Installing WMI..............................................................................................................70 Core Components of WMI ..............................................................................72 Windows Management Instrumentation............................................79 WMI Management Applications.................................................................82 Types of Providers..................................................................................................87 Event Handling...........................................................................................................89 Event Consumer.......................................................................................................90 WMI Security................................................................................................................91 The WMI Query Language.............................................................................95 Summary........................................................................................................................103 TEN FAST FACTS: WINDOWS MANAGEMENT INSTRUMENTATION.........................................................................................103 CHAPTER 4. A GUIDED TOUR OF THE COMMON INFORMATION MODEL REPOSITORY .....................................104 Metadata.........................................................................................................................105 Dynamic and Static Data................................................................................106 Dynamic Data and the CIM Repository ...........................................107 The Common Information Model............................................................108 Namespaces...............................................................................................................112 Using the CIMV2 Namespace...................................................................112 WMI Namespaces and the CIM repository ..................................113
Defining and Using Your Own Namespace.................................115 Namespaces and Schemas ........................................................................115 Using Existing Schemas.................................................................................116 Subclassing and Instantiating Existing Classes in the CIMV2 Namespace..............................................................................................116 Modifying Existing Classes ..........................................................................117 MOF Class Declaration....................................................................................118 Qualifiers ........................................................................................................................119 Flavors..............................................................................................................................120 Custom Qualifiers..................................................................................................121 User-Defined Qualifiers ...................................................................................122 Intrinsic Data Types.............................................................................................122 Instance Creation...................................................................................................123 A Compileable MOF File ................................................................................124 ActiveX Components..........................................................................................127 Let the Tour Begin!...............................................................................................128 The Class Explorer Explained...................................................................130 System Properties.................................................................................................135 Object and Property Qualifiers .................................................................136 CIM Studio Functions ........................................................................................139 Places of Interest within the CIM repository................................145 Tutorial: Creating a Namespace and Adding Classes, Properties, and an Association ................................................................148 The Wizards................................................................................................................149 Summary........................................................................................................................150 TEN FAST FACTS: CIM REPOSITORY...................................150 CHAPTER 5. DEVELOPING CLASS SCHEMAS..............151 Schema Design and System Manageability ...............................152 Case Study: Client/Server E-mail Package.................................154 The Unified Modeling Language.............................................................155 Learning the CIM Schema and Win32 Extended Schemas.........................................................................................................................156 The Windows Installer and WMI.............................................................158
Schema Design by Teams vs. by Single Developers........159 The Unified Modeling Language in Schema Design ..........160 A Brief Introduction to UML Object Modeling.............................160 Interpreting the Common Model in UML.........................................164 The Schema Design Road Map..............................................................166 WMI Topology Design.......................................................................................169 Schema Design Phase.....................................................................................172 Representing the PostOffice Schema in UML ..........................197 Summary........................................................................................................................198 TEN STARTING SCHEMA DESIGN TIPS................................198 CHAPTER 6. METHOD DESIGN AND SCHEMA CLASS POSITIONING ......................................................................................199 Properties vs. Methods ....................................................................................199 Methods, Operations, and Functions.................................................200 Step 5: Define Methods...................................................................................201 Step 6: Check Schema Design................................................................213 Final Step: Positioning Classes...............................................................217 Step-by-Step CIMV2 Namespace Class Positioning .........218 Putting Class Placement Theory into Practice .........................222 Namespace and Schema Placement ................................................224 The Applications Namespace....................................................................225 MOF Creation and Testing...........................................................................230 Implementing the Schema: WMI API Calls vs. MOF Code ..................................................................................................................................................231 Multilanguage Support......................................................................................231 The Post Office Schema in MOF ...........................................................233 PO_PostOfficeHasSettings MOF File ...............................................246 Testing..............................................................................................................................248 Schema Deployment..........................................................................................249 Summary........................................................................................................................249 SCHEMA DESIGN AND POSITIONING Q & A...............249
CHAPTER 7. DEVELOPING MANAGEMENT APPLICATIONS ......................................................................................................250 Getting Started .........................................................................................................251 Object Paths Explained ...................................................................................253 Getting an Object...................................................................................................255 Enumerating Objects..........................................................................................256 Creating an Object................................................................................................258 Updating Objects....................................................................................................261 Deleting an Object ................................................................................................262 Performing Queries..............................................................................................264 Making Method Calls..........................................................................................266 Manipulating Object Properties................................................................272 Manipulating Array Object Properties................................................277 Accessing Objects from Object Properties...................................278 Making Semisynchronous Calls..............................................................281 Making Asynchronous Calls........................................................................285 WMI Error Messages .........................................................................................288 Overview of Events..............................................................................................289 Intrinsic Events.........................................................................................................291 Extrinsic Events.......................................................................................................292 Timer Events ..............................................................................................................293 How to Subscribe to Events........................................................................295 Writing Applications to Receive Semisynchronous Events ..................................................................................................................................................297 Writing Applications to Receive Asynchronous Events ...299 More on Security ....................................................................................................302 Classes that Require Specific Security Privileges ................304 Localized Namespaces....................................................................................307 Overview of High Performance Classes.........................................310 Writing Applications to Access High-Performance Data.310 Access High-Performance Enumerated Data ...........................313 Summary........................................................................................................................314
TEN FAST FACTS: DEVELOPING C++/COM MANAGEMENT APPLICATIONS:....................................................315 CHAPTER 8. DEVELOPING .NET MANAGEMENT APPLICATIONS ......................................................................................................315 Getting Started .........................................................................................................316 Getting a Management Object..................................................................317 Enumerating Management Objects.....................................................323 Creating a Management Object ..............................................................325 Updating Management Objects...............................................................328 Deleting a Management Object...............................................................329 Performing Queries..............................................................................................331 Making Method Calls..........................................................................................335 Manipulating Management Object Properties...........................340 Manipulating Array Object Properties................................................344 Accessing Objects from Object Properties...................................345 Making Asynchronous Calls........................................................................347 Overview of Events..............................................................................................351 Writing Applications to Receive Asynchronous Events ...352 Writing Applications to Receive Semisynchronous Events ..................................................................................................................................................355 Managing Connections to WMI................................................................357 Summary........................................................................................................................360 TEN FAST FACTS: DEVELOPING .NET MANAGEMENT APPLICATIONS......................................................361 CHAPTER 9. DEVELOPING MMC SNAP-INS ..........362 Snap-in Architecture ...........................................................................................363 Getting Started .........................................................................................................365 Snap-in Implementation Basics...............................................................369 Let's Make a Snap-in .........................................................................................372 Implementing IComponentData................................................................................373 Implementing IComponent........................................................................................375 The Root Item and General Item Basics ........................................376
分享到:
收藏