0

gwmi -Query "SELECT * FROM Win32_Service WHERE Name LIKE '%Logon%'" (works fine)

returns some set of results,
But when I run a similar query on some other class REF property ex: Win32_DependentService over Antecedent property the query is invalid.

gwmi -Query "select * from Win32_DependentService where Antecedent like '%'" (doesn't work) (this is for example, my intention is not to display all the entries in Win32_DependentService, and I have a proper like clause for that.)

the above one tells the query tells invalid.

Win32_DependentService from MSDN

class Win32_DependentService : CIM_ServiceServiceDependency
{
  Win32_BaseService REF Antecedent;
  Win32_BaseService REF Dependent;
  uint16            TypeOfDependency;
};

gwmi -Query "select * from Win32_DependentService where Antecedent='\\\\XXXXXXX-machine\\root\\cimv2:Win32_SystemDriver.Name=`"ibbus`"'" this gives proper results.

Why is it so? Is it because Antecedent property is REF?

Please tell me the behavior with proper examples if possible, also how to use the 'like' in this case.

sri
  • 1,005
  • 1
  • 12
  • 26

3 Answers3

3

Sounds like you just need to use "NOT Antecedent.Name IS NULL" if you want to return all records where this property has a value (i.e. isn't blank).

Jim
  • 31
  • 2
0

I'm not really familiar with what you are trying to do so forgive me if this is completely off the mark but the first thing that comes to mind is that the name of a windows service is a simple string whereas antecedent is a class so as you show in your more specific where clause you have to provide some kind of path to get the query to work, in short maybe the wildcard only works on strings.

Have you tried something like

gwmi -Query "select * from Win32_DependentService where Antecedent.Name like '%'"

Not sure if this would handle services with no antecedents or id it is even valid syntax.

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
  • It didn't work, but the feeling i have is if it can do '=' comparison it should be able to do 'like' also. – sri Sep 03 '12 at 14:20
0

The LIKE operator determines if a string (not null but at least 1 or more characters) matches a pattern. So the statement - WHERE value LIKE '%' - doesn't make sense as that value has nothing to check against. See WQL LIKE operator: http://msdn.microsoft.com/en-us/library/windows/desktop/aa392263(v=vs.85).aspx

MacG
  • 271
  • 2
  • 4
  • '%' should match all strings, that's what even MSDN says, if should return all instances when used. When I replace '%Logon%' with '%' it returns all instances of Win32_service. – sri Sep 04 '12 at 08:54