SlideShare a Scribd company logo
1 of 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!

More Related Content

Similar to 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
 

Similar to 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
 

Recently uploaded

QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 

Recently uploaded (20)

QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 

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!