WMI object paths containing a right brace (}) character

November 03rd, 2005 - 05:16 pm ET by Bill Stewart | Report spam
Hi all,

I've encountered what seems to be a limitation in how WMI reads object
paths when I use an ASSOCIATORS OF WQL query or the AssociatorsOf()
method. If the object path contains the right curly brace character (}),
WMI always returns 0x80041017 (invalid query syntax).

To reproduce this issue, I created a directory called C:\Test}Dir and
put two subdirectories in it called Dir1 and Dir2. Next, I ran the
following short script:

Dim Computer, WMI, Subdirs, Subdir

Computer = "."

Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" _
& Computer & "/root/cimv2")

Set Subdirs = WMI.ExecQuery("Associators Of " _
& "{Win32_Directory.Name='C:\Test}Dir'} Where " _
& "AssocClass=Win32_Subdirectory ResultRole=PartComponent")

For Each SubDir In Subdirs
WScript.Echo Subdir.Name
Next

If I rename the directory and remove the "}" character (and edit the
query in the script accordingly), it behaves as expected and enumerates
the subdirectories.

There's no mention of "}" being a special character, or how to escape it
to prevent this, in Microsoft's reference:

http://msdn.microsoft.com/library/d...ements.asp

Using a double quote character (") in the object path in place of the
single quote doesn't work either; WMI returns 0x8004103A (invalid object
path).

Has anyone else encountered this issue? Am I doing something wrong, is
this a bug, or is there a workaround?

Thanks

Bill Stewart
email Follow the discussionReplies 1 replyReplies Make a reply

Replies

#1 Bill Stewart
November 04th, 2005 - 10:56 am ET | Report spam
Bill Stewart wrote:

I've encountered what seems to be a limitation in how WMI reads object
paths when I use an ASSOCIATORS OF WQL query or the AssociatorsOf()
method. If the object path contains the right curly brace character (}),
WMI always returns 0x80041017 (invalid query syntax).

To reproduce this issue, I created a directory called C:\Test}Dir and
put two subdirectories in it called Dir1 and Dir2. Next, I ran the
following short script:

Dim Computer, WMI, Subdirs, Subdir

Computer = "."

Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" _
& Computer & "/root/cimv2")

Set Subdirs = WMI.ExecQuery("Associators Of " _
& "{Win32_Directory.Name='C:\Test}Dir'} Where " _
& "AssocClass=Win32_Subdirectory ResultRole=PartComponent")

For Each Subdir In Subdirs
WScript.Echo Subdir.Name
Next

If I rename the directory and remove the "}" character (and edit the
query in the script accordingly), it behaves as expected and enumerates
the subdirectories.

There's no mention of "}" being a special character, or how to escape it
to prevent this, in Microsoft's reference:

http://msdn.microsoft.com/library/d...ements.asp

Using a double quote character (") in the object path in place of the
single quote doesn't work either; WMI returns 0x8004103A (invalid object
path).

Has anyone else encountered this issue? Am I doing something wrong, is
this a bug, or is there a workaround?



For reference, I've discovered an alternative syntax that works. Rather
than using single quotes (') to delimit the object path, you can indeed
use double quotes, but this requires escaping backslashes "\" with a
second backslash.

This script works:

Dim Computer, WMI, Subdirs, Subdir

Computer = "."

Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" _
& Computer & "/root/cimv2")

Set Subdirs = WMI.ExecQuery("Associators Of " _
& "{Win32_Directory.Name=""C:\\Test}Dir""} Where " _
& "AssocClass=Win32_Subdirectory ResultRole=PartComponent")

For Each Subdir In Subdirs
WScript.Echo Subdir.Name
Next

Thanks

Bill Stewart

Similar topics