WMI - 'like' in select

  • Thread starter Thread starter Gionni
  • Start date Start date
G

Gionni

Hello everyone,
I have to query a subset of services to get their status.
Is it possibile to make a query like this:

Dim objectQuery As New WqlObjectQuery("select * from Win32_Services
where Name like 'SDSReceiveFunction*'")

'like' clause seems to not work. How could I get all services with the
name starting with SDSReceiveFunction?

Thanks and cheers, Gionni
 
You need to use the '%' wild card character, which matches any number of
characters. I dont' think the '*' character does anything in SQL.

As an aside, this is really a SQL questions, and has nothing to do with
..NET.
 
Marina said:
You need to use the '%' wild card character, which matches any number of
characters. I dont' think the '*' character does anything in SQL.

As an aside, this is really a SQL questions, and has nothing to do with
.NET.

It has everything to do with .NET.
Did you read the subject line, and did you take a look at the code snip,
doesn't that look like VB.NET code.
Do you really thing SQL syntax is only tied to Databases?

Willy.
 
Gionni said:
Hello everyone,
I have to query a subset of services to get their status.
Is it possibile to make a query like this:



'like' clause seems to not work. How could I get all services with the
name starting with SDSReceiveFunction?

Thanks and cheers, Gionni

Try this and take a look at the MSDN WMI doc's.

Dim objectQuery As New WqlObjectQuery("select * from Win32_Services
where Name like 'SDSReceiveFunction%")

Willy.
 
Willy Denoyette said:
Dim objectQuery As New WqlObjectQuery("select * from Win32_Services
where Name like 'SDSReceiveFunction%")

I tried, but it does not work.
It returns an "Invalid query" exception.

Cheers, Gionni
 
What OS are you running this on?
The LIKE syntax is only supported on XP and W2K3.

Willy.
 
Hi,

I tested this line on my machine and it did not work:

select * from Win32_Services where Name like 'SQL%'

after closer inspection I noticed that you had Win32_Services and not
Win32_Service. this line works (I am running XP)

select * from Win32_Service where Name like 'SQL%'

Hope that helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top