SlideShare une entreprise Scribd logo
1  sur  32
Application Instrumentation with WMI
About Nick Schweitzer Senior Consultant for SpiderLogic in Milwaukee Milwaukee Area Consultant for 12+ years B.S. in Computer Engineering from MSOE Around the Internets: thecodingmonkey.net (Geek/Technical) nickschweitzer.net (Life/Politics) flickr.com/photos/schweitn (Amateur Photography) twitter.com/NickSchweitzer (Real Time) facebook.com/NickSchweitzer (Meta)
Agenda What is WMI? WMI Architecture Querying System State with WMI Instrumenting .NET Applications with WMI WMI Tools Cool Uses for WMI WMI Related Projects and Resources
Warning This is Not Bleeding Edge Technology You Could Have Been Doing this For the Last 8 Years… If You Knew It Was There.
What is WMI? Windows Management Instrumentation Microsoft’s Implementation of WBEM (Web-Based Enterprise Management) Allows Machine and Software State to be Exposed to Local and Remote Queries for Enhanced Enterprise Management
Why Instrument for WMI? Provides Many Methods to Query Application State .NET Query (System.Management namespace) Powershell MOM/SCOM Monitoring Visual Studio Analyzer Inter-process Signaling & Communication Useful for Monitoring and Debugging Services w/o User Interfaces Watchdog Processes and Redundant/Failover Services
Common Information Model (CIM) Language Independent Model for Representing Enterprise Objects Supports Inheritance & Object Relationships  Supports Schemas for Objects CIM_* (Core/Common Classes) Win32_* (Windows Implementation Specific Classes) Can Create User Defined Schemas
WMI Namespaces Independent of .NET Namespaces Best Practice is to create a Root Namespace for Company and Sub-Namespaces for applications or services User Access Security can be set at a Namespace level on each machine. Win32_* Objects in ROOTIMV2 Used for Querying Machine & Operating System state
WMI Query Language (WQL) SQL Subset Used to Query WMI Repository Get Name of All Running Services SELECT DisplayName FROM Win32_Service WHERE State = 'Running' Get Local Computer Name SELECT Name FROM Win32_ComputerSystem Get List of All Local Groups SELECT * FROM Win32_Group WHERE LocalAccount = True
Subscribing to Events with WQL Can Be Notified of the Following: Instance Creation and Deletion Property Changes Custom Events Example – New Process Notification SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' WITHIN Keyword Defines Polling Frequency in Seconds
Demo: WQL in Powershell
.NET Instrumentation with WMI Attribute Based Two Sets of Attributes in One Assembly System.Management.Instrumentation Both sets can be used together in one application. Both sets cannot be used together in one class. Requires Assembly Registration
Original WMI Attributing (v1) Properties Instrumented by Default Resulting WMI objects can only be used for Query Can Only Instrument Properties that are Value Types Cannot Expose Methods Available for Use in .NET 1.0 and later
Custom WMI Classes (v1) InstrumentationClass Marks a class as being Instrumented All properties are Instrumented by Default Can also derive from Instance class instead IgnoreMember Marks a property as being not Instrumented Required for properties that cannot be Instrumented Instrumentation.Publish() Makes Object Available to WMI Repository
Custom WMI Events Only Available in v1 InstrumentationClass InstrumentationType = Event Call Instrumentation.Fire()to Raise Event Derive class from BaseEvent Call Fire()method to Raise Event Events Can Only Reference WMI Primitives
WMI Registration (v1) Instrumented Attribute Assembly Level Attribute Specify Namespace DefaultManagementProjectInstaller Use InstallUtil.exe to register Namespace and CIM Schema
New WMI Attributing (v2) Properties Instrumented only if Attributed Can Create New .NET objects using WMI Invoke Constructors, Methods, Change Properties, etc. Can Instrument Properties that are Reference Types (if also Instrumented) Available for Use in .NET 3.5 and later.
Custom WMI Classes (v2) ManagementEntity Marks a Class as being instrumented (equivalent to InstrumentationClass in v1) ManagementKey Marks a Property as being a unique identifier ManagementProbe/ManagementConfiguration Marks a Property as being instrumented MangementBind Marks a Method/Constructor available to WMI for object creation ManagementTask Marks a Method available to WMI for invocation InstrumentationManager.Publish() Makes Object Available to WMI Repository
WMI Registration (v2) WmiConfiguration Assembly Level Attribute Specify Namespace HostingModel Use Decoupled for Application Instrumenation DefaultManagementInstaller Use InstallUtil.exe to register Namespace and CIM Schema
Runtime WMI Registration Registration Possible w/o InstallUtil.exe Registering All Types in an Assembly Instrumentation.RegisterAssembly (v1) InstrumentationManager.RegisterAssembly (v2) InstrumenationManager.UnregisterAssembly (v2) Registering Individual Classes InstrumentationManager.RegisterType(v2) InstrumentationManager.UnregisterType(v2)
Which Attribute System? If your application does not require v2 WMI Attributes, then don’t use them. The object management is not worth the hassle.
Demo: Instrumenting .NET Applications
WMI in WCF Used to Turn On WCF Diagnostics at Runtime Must Enable WMI in Configuration File:<system.serviceModel> …  <diagnostics wmiProviderEnabled="true" /> … </system.serviceModel> Published in rooterviceModel AppDomainInfo Object LogMalformedMessages : Boolean LogMessagesAtServiceLevel : Boolean LogMessagesAtTransportLevel : Boolean
WMI in WCF Continued Using Powershell to Get WCF Diagnostic Settings Get Diagnostic Settings:get-wmiobject -class "AppDomainInfo" -namespace "rootervicemodel" -computername "." Changes Made at Runtime Not Stored in Configuration File – Only Valid During Current Run
WMI “Productivity” Tools Windows Management Instrumentation Tester Used to Browse and Query WMI Objects and Schemas wbemtest.exe WMI Code Creator Utility to Quickly Generate WQL Code in Multiple Languages Management Strongly Typed Class Generator  Generates Strongly Types Classes for Querying and Accessing WMI objects mgmtclassgen.exe (Windows SDK) WMI CIM Studio ActiveX powered tool used to browse WMI objects on local machine.
Demo: WMI Tools
Custom MMC Snap-Ins Requires MMC 3.0 (Separate Install for Win XP) Run mmcperf.exe Before Installing a New Snap-In Can Hook Into Computer Management if you know the right GUID’s Snap-In DLL’s Registered using InstallUtil.exe Relatively Easy to Determine Target Computer to Query Provides Framework and Base Classes for Creating Uniform Looking MMC Snap-In UI
Demo: MMC Snap-In with .NET
Presentation Resources Presentation Slides and Code Samples www.thecodingmonkey.net Microsoft Downloads WMI CIM Studio WMI Code Creator MMC Extensible Node GUID’s Computer Management GUID List Server Manager GUID List
Other Online Resources Windows Management Infrastructure Blog http://blogs.msdn.com/wmi/ Linq to WMI Project http://linq2wmi.codeplex.com Not Actively Maintained, and Somewhat Incomplete
Questions? Help Make My Presentations Better Please Fill Out an Evaluation Form! Opinions are Completely Anonymous (Unless You Don’t Want Them to Be) Thank You!

Contenu connexe

Similaire à Application Instrumentation with WMI

Net framework session03
Net framework session03Net framework session03
Net framework session03Vivek chan
 
Using WatiN in Sharepoint
Using WatiN in SharepointUsing WatiN in Sharepoint
Using WatiN in Sharepointsadomovalex
 
Microsoft Virtualization View
Microsoft Virtualization View Microsoft Virtualization View
Microsoft Virtualization View sanjoysanyal
 
WinJS at NYC Code Camp 2012
WinJS at NYC Code Camp 2012WinJS at NYC Code Camp 2012
WinJS at NYC Code Camp 2012Dmitri Artamonov
 
VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...
VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...
VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...IJNSA Journal
 
Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...
Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...
Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...Frédéric Harper
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEBenjamin Cabé
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Christian Johansen
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface ComponentsAhmad Hamid
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsPeter Gfader
 
Managing Hyper-V With PowerShell
Managing Hyper-V With PowerShellManaging Hyper-V With PowerShell
Managing Hyper-V With PowerShellRavikanth Chaganti
 
Aws meetup systems_manager
Aws meetup systems_managerAws meetup systems_manager
Aws meetup systems_managerAdam Book
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAViktor Gamov
 
Windows 7 Application Compatibility
Windows 7 Application CompatibilityWindows 7 Application Compatibility
Windows 7 Application Compatibilitymicham
 
automation framework
automation frameworkautomation framework
automation frameworkANSHU GOYAL
 

Similaire à Application Instrumentation with WMI (20)

Net framework session03
Net framework session03Net framework session03
Net framework session03
 
Using WatiN in Sharepoint
Using WatiN in SharepointUsing WatiN in Sharepoint
Using WatiN in Sharepoint
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Microsoft Virtualization View
Microsoft Virtualization View Microsoft Virtualization View
Microsoft Virtualization View
 
Dat403 Massie
Dat403 MassieDat403 Massie
Dat403 Massie
 
WinJS at NYC Code Camp 2012
WinJS at NYC Code Camp 2012WinJS at NYC Code Camp 2012
WinJS at NYC Code Camp 2012
 
VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...
VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...
VIRTUAL MACHINES AND NETWORKS – INSTALLATION, PERFORMANCE, STUDY, ADVANTAGES ...
 
Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...
Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...
Toronto User groups workshop - 2013-03-10 - HTML5 & Windows 8, friends with b...
 
Use Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDEUse Eclipse technologies to build a modern embedded IDE
Use Eclipse technologies to build a modern embedded IDE
 
Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)Test-Driven JavaScript Development (JavaZone 2010)
Test-Driven JavaScript Development (JavaZone 2010)
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface Components
 
Rmi
RmiRmi
Rmi
 
Rmi
RmiRmi
Rmi
 
Web services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows FormsWeb services, WCF services and Multi Threading with Windows Forms
Web services, WCF services and Multi Threading with Windows Forms
 
Rmi
RmiRmi
Rmi
 
Managing Hyper-V With PowerShell
Managing Hyper-V With PowerShellManaging Hyper-V With PowerShell
Managing Hyper-V With PowerShell
 
Aws meetup systems_manager
Aws meetup systems_managerAws meetup systems_manager
Aws meetup systems_manager
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIA
 
Windows 7 Application Compatibility
Windows 7 Application CompatibilityWindows 7 Application Compatibility
Windows 7 Application Compatibility
 
automation framework
automation frameworkautomation framework
automation framework
 

Dernier

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Dernier (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Application Instrumentation with WMI

  • 2. About Nick Schweitzer Senior Consultant for SpiderLogic in Milwaukee Milwaukee Area Consultant for 12+ years B.S. in Computer Engineering from MSOE Around the Internets: thecodingmonkey.net (Geek/Technical) nickschweitzer.net (Life/Politics) flickr.com/photos/schweitn (Amateur Photography) twitter.com/NickSchweitzer (Real Time) facebook.com/NickSchweitzer (Meta)
  • 3. Agenda What is WMI? WMI Architecture Querying System State with WMI Instrumenting .NET Applications with WMI WMI Tools Cool Uses for WMI WMI Related Projects and Resources
  • 4. Warning This is Not Bleeding Edge Technology You Could Have Been Doing this For the Last 8 Years… If You Knew It Was There.
  • 5. What is WMI? Windows Management Instrumentation Microsoft’s Implementation of WBEM (Web-Based Enterprise Management) Allows Machine and Software State to be Exposed to Local and Remote Queries for Enhanced Enterprise Management
  • 6. Why Instrument for WMI? Provides Many Methods to Query Application State .NET Query (System.Management namespace) Powershell MOM/SCOM Monitoring Visual Studio Analyzer Inter-process Signaling & Communication Useful for Monitoring and Debugging Services w/o User Interfaces Watchdog Processes and Redundant/Failover Services
  • 7.
  • 8. Common Information Model (CIM) Language Independent Model for Representing Enterprise Objects Supports Inheritance & Object Relationships Supports Schemas for Objects CIM_* (Core/Common Classes) Win32_* (Windows Implementation Specific Classes) Can Create User Defined Schemas
  • 9. WMI Namespaces Independent of .NET Namespaces Best Practice is to create a Root Namespace for Company and Sub-Namespaces for applications or services User Access Security can be set at a Namespace level on each machine. Win32_* Objects in ROOTIMV2 Used for Querying Machine & Operating System state
  • 10. WMI Query Language (WQL) SQL Subset Used to Query WMI Repository Get Name of All Running Services SELECT DisplayName FROM Win32_Service WHERE State = 'Running' Get Local Computer Name SELECT Name FROM Win32_ComputerSystem Get List of All Local Groups SELECT * FROM Win32_Group WHERE LocalAccount = True
  • 11. Subscribing to Events with WQL Can Be Notified of the Following: Instance Creation and Deletion Property Changes Custom Events Example – New Process Notification SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' WITHIN Keyword Defines Polling Frequency in Seconds
  • 12. Demo: WQL in Powershell
  • 13. .NET Instrumentation with WMI Attribute Based Two Sets of Attributes in One Assembly System.Management.Instrumentation Both sets can be used together in one application. Both sets cannot be used together in one class. Requires Assembly Registration
  • 14. Original WMI Attributing (v1) Properties Instrumented by Default Resulting WMI objects can only be used for Query Can Only Instrument Properties that are Value Types Cannot Expose Methods Available for Use in .NET 1.0 and later
  • 15. Custom WMI Classes (v1) InstrumentationClass Marks a class as being Instrumented All properties are Instrumented by Default Can also derive from Instance class instead IgnoreMember Marks a property as being not Instrumented Required for properties that cannot be Instrumented Instrumentation.Publish() Makes Object Available to WMI Repository
  • 16. Custom WMI Events Only Available in v1 InstrumentationClass InstrumentationType = Event Call Instrumentation.Fire()to Raise Event Derive class from BaseEvent Call Fire()method to Raise Event Events Can Only Reference WMI Primitives
  • 17. WMI Registration (v1) Instrumented Attribute Assembly Level Attribute Specify Namespace DefaultManagementProjectInstaller Use InstallUtil.exe to register Namespace and CIM Schema
  • 18. New WMI Attributing (v2) Properties Instrumented only if Attributed Can Create New .NET objects using WMI Invoke Constructors, Methods, Change Properties, etc. Can Instrument Properties that are Reference Types (if also Instrumented) Available for Use in .NET 3.5 and later.
  • 19. Custom WMI Classes (v2) ManagementEntity Marks a Class as being instrumented (equivalent to InstrumentationClass in v1) ManagementKey Marks a Property as being a unique identifier ManagementProbe/ManagementConfiguration Marks a Property as being instrumented MangementBind Marks a Method/Constructor available to WMI for object creation ManagementTask Marks a Method available to WMI for invocation InstrumentationManager.Publish() Makes Object Available to WMI Repository
  • 20. WMI Registration (v2) WmiConfiguration Assembly Level Attribute Specify Namespace HostingModel Use Decoupled for Application Instrumenation DefaultManagementInstaller Use InstallUtil.exe to register Namespace and CIM Schema
  • 21. Runtime WMI Registration Registration Possible w/o InstallUtil.exe Registering All Types in an Assembly Instrumentation.RegisterAssembly (v1) InstrumentationManager.RegisterAssembly (v2) InstrumenationManager.UnregisterAssembly (v2) Registering Individual Classes InstrumentationManager.RegisterType(v2) InstrumentationManager.UnregisterType(v2)
  • 22. Which Attribute System? If your application does not require v2 WMI Attributes, then don’t use them. The object management is not worth the hassle.
  • 23. Demo: Instrumenting .NET Applications
  • 24. WMI in WCF Used to Turn On WCF Diagnostics at Runtime Must Enable WMI in Configuration File:<system.serviceModel> … <diagnostics wmiProviderEnabled="true" /> … </system.serviceModel> Published in rooterviceModel AppDomainInfo Object LogMalformedMessages : Boolean LogMessagesAtServiceLevel : Boolean LogMessagesAtTransportLevel : Boolean
  • 25. WMI in WCF Continued Using Powershell to Get WCF Diagnostic Settings Get Diagnostic Settings:get-wmiobject -class "AppDomainInfo" -namespace "rootervicemodel" -computername "." Changes Made at Runtime Not Stored in Configuration File – Only Valid During Current Run
  • 26. WMI “Productivity” Tools Windows Management Instrumentation Tester Used to Browse and Query WMI Objects and Schemas wbemtest.exe WMI Code Creator Utility to Quickly Generate WQL Code in Multiple Languages Management Strongly Typed Class Generator Generates Strongly Types Classes for Querying and Accessing WMI objects mgmtclassgen.exe (Windows SDK) WMI CIM Studio ActiveX powered tool used to browse WMI objects on local machine.
  • 28. Custom MMC Snap-Ins Requires MMC 3.0 (Separate Install for Win XP) Run mmcperf.exe Before Installing a New Snap-In Can Hook Into Computer Management if you know the right GUID’s Snap-In DLL’s Registered using InstallUtil.exe Relatively Easy to Determine Target Computer to Query Provides Framework and Base Classes for Creating Uniform Looking MMC Snap-In UI
  • 29. Demo: MMC Snap-In with .NET
  • 30. Presentation Resources Presentation Slides and Code Samples www.thecodingmonkey.net Microsoft Downloads WMI CIM Studio WMI Code Creator MMC Extensible Node GUID’s Computer Management GUID List Server Manager GUID List
  • 31. Other Online Resources Windows Management Infrastructure Blog http://blogs.msdn.com/wmi/ Linq to WMI Project http://linq2wmi.codeplex.com Not Actively Maintained, and Somewhat Incomplete
  • 32. Questions? Help Make My Presentations Better Please Fill Out an Evaluation Form! Opinions are Completely Anonymous (Unless You Don’t Want Them to Be) Thank You!