WMI Programming with Visual Basic.NET: What is the WQL? (Page 1 of 4 )
The goal of this series is to introduce Microsoft Windows Management Instrumentation (WMI) and get you up and running as quickly as possible, using it to manage your system through the WMI programming using .NET. This article covers querying WMI with the Windows Query Language.
You can download the zip of entire Visual Studio.NET solution (developed for this article)
here.
The first part of this series covered the basics of WMI and how to access WMI information from Visual Basic.NET (both locally and remotely). In this article, I will introduce you to the concept of WQL together with types of WQL queries.
The first article in this series gave you the details for creating a Visual Studio.NET solution for WMI, from scratch. This information will not be repeated in any of the future articles in this series.
Querying WMI with WQL (local environment)
Anyone who works in the IT sector would definitely hear about SQL. Structured Query Language (SQL) is a great querying language for relational databases. As SQL is used for relational databases, WQL is used to query WMI information. But, one should consider that it is not as robust as SQL. In this article, I will cover only the basics of WQL rather than going into very great depth at this moment.
The WMI Query Language (WQL) is a subset of the American National Standards Institute Structured Query Language (ANSI SQL)—with minor semantic changes. We can just consider WQL as something like “WMI + SQL = WQL”.
The following is a small example which demonstrates a simple SELECT statement in WQL.
DimsearcherAsNewManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
DimdisksAsManagementObjectCollection = searcher.Get()
DimdiskAsManagementObject
DimarDisksAsNewArrayList
ForEachdiskIndisks
arDisks.Add(disk("deviceid").ToString())
Nextdisk
Me.lstDrives.Items.AddRange(arDisks.ToArray)
You can obtain the above code from “form1.vb” file in the zip file included for download. If you observe the above code and compare it with my previous examples (present in part one), there exists only a small difference, as follows:
DimsearcherAsNewManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
DimdisksAsManagementObjectCollection = searcher.Get()
In the first statement, I am using a new class named “ManagementObjectSearcher”, used to retrieve a collection of management objects based on a specified query. The class got a method “get()” to retrieve all instances of objects based on the query specified. And I hope the rest is the same.
Next: Querying WMI with WQL (remote environment) >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee