Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Introduction to WQL: SQL for WMI
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Introduction to WQL: SQL for WMI
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2007-05-16

    Table of Contents:
  • Introduction to WQL: SQL for WMI
  • Data Queries
  • Event Queries
  • Schema Queries

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to WQL: SQL for WMI - Data Queries


    (Page 2 of 4 )

    Data Queries

    These are the most common type of WMI query.  Data queries poll WMI for specific information by returning property values.  These are generally also the simplest type of queries.

    strComputer = "."

    Set objWMIService = GetObject("winmgmts:" & strComputer & "rootCIMV2")

    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NTLogEvent" _

        & " WHERE Logfile = 'Application'")

    This is a relatively simple query.  We begin by connecting to WMI’s CIMV2 Providers.  Then, we make use of the WMIService’s ExecQuery method to issue the query whose results are returned as a collection of objects.  The query, which is passed as a string, looks like the following:

    SELECT * FROM Win32_NTLogEvent WHERE Logfile = 'Application'

    We want to SELECT all (*) items from the Win32_NTLogEvent class WHERE the Logfile property is equal to “Application.”

    All queries begin with the SELECT keyword.  The next piece of the query determines how much information is returned about each object.  The wildcard indicates that all available information should be returned.

    Next is the FROM keyword.  This tells WMI which of the Provider’s classes should be polled.  In our example, the Win32NTLogEvent class houses all of the event log entries.

    This example also makes use of a WHERE clause to further control what information is returned.  The query will only return items from our class whose Logfile property matches the string “Application.”  Notice that strings use single quotes, and that this is a strict match.  Items “containing” this string will not be returned.

    To perform a partial match in WQL, make use of the LIKE keyword in place of the = operator.

    A WHERE clause must be in the form of a conditional statement.  Only those items that evaluate to True will be returned.  Executing this query will return a collection of objects representing each entry in the Windows NT Application Event Log.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · In order to harness the power of WMI in your scripts, you'll need to be able to...
     

    WINDOWS SCRIPTING ARTICLES

    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway