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\"')
Ultimately I am trying to delete or rename a folder on a remote machine that may contain a file that is open by the user, but it seems as though this whole thing is a non-starter
> 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
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:
c = wmi.WMI ("svr-heat")
for d in c.wmi.ExecQuery ("""
SELECT * FROM Win32_Directory
WHERE Name = 'c:\\\\temp'
directory = wmi._wmi_object (d)
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 (...)