Click here to Skip to main content
15,895,746 members
Articles / Operating Systems / Windows
Article

WQL DataProvider for ADO.NET

Rate me:
Please Sign up or sign in to vote.
4.07/5 (8 votes)
1 Sep 20041 min read 65.1K   3.5K   29   4
WQL DataProvider for ADO.NET

Introduction

WQL DataProvider is an ADO.Net data provider, so you can use it just like usual MS SQL DataProvider, but for WQL (WMI + SQL = WQL). This DataProvider supports SELECT, ASSOCIATORS and REFERENCES queries. Doesn't support event queries.

How to use it..

C#
using WQLData;
//.............
//.............
WQLConnection connection = new WQLConnection(
    String.Format(@"Server:{0};User:{1\2};Password:{3}", 
    server, doamin, user, password));
DataSet dataSet = new DataSet("WQLDataSet");
WQLDataAdapter adapter = new WQLDataAdapter(
    "SELECT * FROM Win32_LogicalDisk", WQLContext.Connection);
adapter.Fill(dataSet, "LogicalDisks");
//.............
//.............

Demo application - WQL Analyzer

Using "WQL Analyzer" you can :
  • browse classes, properties, qualifiers;
  • run WQL queries (locally or remotely);
  • save results as XML or HTML;
  • connect to remote computer;
  • export class description to XML or HTML;
  • automatically generate the "SELECT" query (double click on class name);

Image 1

Some WQL Examples :

Query :

SQL
SELECT __CLASS, __SUPERCLASS, __DYNASTY
FROM Meta_Class 
WHERE __DYNASTY = "CIM_PhysicalCapacity" 

Result :

__CLASS__SUPERCLASS__DYNASTY
CIM_PhysicalCapacityCIM_PhysicalCapacity
CIM_MemoryCapacityCIM_PhysicalCapacityCIM_PhysicalCapacity

Query :

SQL
SELECT DeviceID, FileSystem, Size, FreeSpace, 
    Compressed, Description, MediaType
FROM Win32_LogicalDisk
WHERE MediaType = 12

Result :

DeviceIDFileSystemSizeFreeSpaceCompressedDescriptionMediaType
C:NTFS12068872192185409536FalseLocal Fixed Disk12
D:NTFS12068872192185409536FalseLocal Fixed Disk12
O:NTFS12068872192185409536FalseLocal Fixed Disk12

Analyzer also supports ASSOCIATORS and REFERENCES queries. For example :

SQL
ASSOCIATORS OF {Win32_LogicalDisk.DeviceID="C:"}
WHERE ClassDefsOnly

REFERENCES OF {Win32_NetworkAdapter.DeviceID="0"} 
WHERE resultclass = Win32_NetworkAdapterSetting requiredQualifier = Dynamic

Note : Analyzer doesn't support Event queries

Current version support some extension (not supported in stantart WQL)

SQL
Invoke method :
      
CALL [\\server\root\cimv2:Win32_Process.Handle="2236"].Terminate(Reason=0)
 
   
Update property :
      
UPDATE Win32_Environment      
SET VariableValue = 'Hi2'      
WHERE __PATH='\\EPNL007\root\cimv2:Win32_Environment.Name="Test",
  UserName="server\\user"'
   

SELECT TOP :
      
SELECT TOP 50 __PATH, Logfile, RecordNumber, EventType,InsertionStrings, 
  Message, SourceName, TimeGenerated
FROM Win32_NTLogEvent     
WHERE  Logfile = 'Application'

Order By :
    
SELECT __PATH, Caption, ExecutablePath, CreationDate,KernelModeTime, 
  ProcessId, ParentProcessId, Priority, ThreadCount, VirtualSize
FROM Win32_Process      
ORDER BY Caption ASC

Run Query on remote computer

Image 2

Export Classes descriptions to XML or HTML

Image 3

Logging

You can configure the error logging in WQLAnalyzer.exe.config. Application uses log4net library for logging in.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralCan't execute and build in on Windows 7 Pin
jeronevw2-Aug-10 8:38
jeronevw2-Aug-10 8:38 
GeneralLimitations with WQL query syntax Pin
daluu30-Jun-09 20:04
daluu30-Jun-09 20:04 
Question__PATH In Query Pin
wzink13-Sep-08 5:54
wzink13-Sep-08 5:54 
GeneralHelp me Pin
dharani23-Nov-04 23:36
dharani23-Nov-04 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.