WMI Programming with Visual Basic.NET: What is the WQL? - Querying WMI with WQL (remote environment)
(Page 2 of 4 )
The first article of the series introduced the concept of remote connectivity through WMI. If you really don’t have any idea about remote connectivity through WMI, I suggest you read it. The same concept is being implemented here, but with a mixture of WQL in between!
Let us consider the following program:
DimoptionsAsNewConnectionOptions
options.Username = "administrator"
options.Password = ""
DimscopeAsNewManagementScope("\\hostname\root\cimv2", options)
DimsearcherAsNewManagementObjectSearcher(scope,NewSelectQuery("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 the “form2.vb” file in the zip included for download. The above program is just the combination of the previous section and the last section from the first article. The only new issue is the following statement:
DimsearcherAsNewManagementObjectSearcher(scope,NewSelectQuery("SELECT * FROM Win32_LogicalDisk"))
In the previous section, we just issued the SELECT statement in the form of a string. But in the above statement, I created an object of class “SelectQuery” to pass the SELECT query. When scope is provided exclusively, the object of “SelectQuery” is necessary, as the “ManagementObjectSearcher” constructor is expecting an object of type “ObjectQuery”. In the previous section, the scope defaults to “root\cimv2” of the local server (or system). Apart from the above statement, the rest is the same.
Make sure that you change the “hostname” in the above program, according to your needs. Similarly, provide your own credentials of username and password to connect the host.
Next: Types of WQL queries >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee