remote machine file query

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

remote machine file query

Trevor Rowland
Hi all,

I'm new to the list, and have a question:

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\"')

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

Any help greatly appreciated!

Trevor





_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|

Re: remote machine file query

Tim Golden-4
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
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32