On 13/02/2012 22:52, Trevor Rowland wrote:
where self.c is a wmi.WMI() connection to a remote machine using my
username and password (I am admin)
why does the line below ALWAYS return an empty list ???

aFile = self.c.Win32_Directory(Name = "C:\\Users"):
print aFile
[]

I have tried various permutations of Name (raw string, single/ double
backslashes, different filenames) but all returned an empty list.
I also tried the Query version:
aTest = self.c.Query('Select * from Win32_Directory WHERE
Name=\"C:\\Users\"')

Ah. That would be a bug in the wmi module, by the look of it.
Basically it's a symptom of backslash madness where every
system in the chain does its own thing with backslashes.

As a workaround (while I try to work around what to do),
you can drop down a level at least for this operation:

<code>
import wmi

c = wmi.WMI ("svr-heat")
for d in c.wmi.ExecQuery ("""
  SELECT * FROM Win32_Directory
  WHERE Name = 'c:\\\\temp'
"""):
  directory = wmi._wmi_object (d)
  break


</code>

The wmi attribute of the WMI connection is the underlying
WMI COM object so you can call any of its methods including
the ubiquious ExecQuery.

The wmi._wmi_object class attempts to wrap any WMI object you can
throw at it. So what you're doing here is temporarily bypassing
the plumbling which underlies the more Python c.Win32_Directory (...)
stuff.

TJG
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to