Cim_Datafile - Find file version

A forum for general discussion of the Python programming language.

Cim_Datafile - Find file version

Postby rcjay272 » Tue Mar 19, 2013 6:08 pm

All,

I am trying to use python to query a file to get the version. Below are examples of the code I am having issues with. I am at a loss and looking for help.
Any pointers would be great.



This code returns nothing.....

Code: Select all
import wmi
getinstance = wmi.WMI()
for f in getinstance.CIM_DataFile (Name="c:\\Windows\\System32\\notepad.exe"):
 print f.version




Code: Select all
def checkNotepadFileVersion(self, table=None):

      if not table:
         table = prettytable.PrettyTable(["Server", "FileName", "File Version"])

      for entry in self.wmi.CIM_Datafile(name='c:\\Windows\\System32\\notepad.exe'):
         table.add_row( [ self.hostname, entry.FileName, entry.Version ] )

      return table   


Thank you,
Rob
Thank you,

Rob
rcjay272
 
Posts: 3
Joined: Tue Mar 19, 2013 5:50 pm

Re: Cim_Datafile - Find file version

Postby setrofim » Tue Mar 19, 2013 6:58 pm

What kind of issue are you having? Please post the full error your getting (or describe the behavior you're obseving vs what you expect).
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Cim_Datafile - Find file version

Postby rcjay272 » Tue Mar 19, 2013 7:09 pm

I get no output when running the code.


When I run the code below I get no output. I am expecting it to output the file version of notepad.exe.

This is a standard call to WMIC on any windows machine....see the output, I want to accomplish the same with python but cannot get it to work.

C:\>wmic datafile where name='c:\\Windows\\system32\\notepad.exe' get version
Version
6.1.7600.16385


Code: Select all
import wmi
getinstance = wmi.WMI()
for f in getinstance.CIM_DataFile (Name='C:\\Windows\system32\notepad.exe'):
 print f.version
Thank you,

Rob
rcjay272
 
Posts: 3
Joined: Tue Mar 19, 2013 5:50 pm

Re: Cim_Datafile - Find file version

Postby setrofim » Tue Mar 19, 2013 7:14 pm

You have some back slashes missing. The name parameter should be either 'C:\\Windows\\system32\\notepad.exe' or r'C:\Windows\system32\notepad.exe'. Also, check the capitalization on 'Name'.
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm

Re: Cim_Datafile - Find file version

Postby rcjay272 » Tue Mar 19, 2013 8:40 pm

I have tried this....

Code: Select all
import wmi
getinstance = wmi.WMI()
for f in getinstance.CIM_DataFile (r'C:\\Windows\\system32\\notepad.exe'):
 print f.version


And this....

Code: Select all
import wmi
getinstance = wmi.WMI()
for f in getinstance.CIM_DataFile (name="C:\\Windows\\system32\\notepad.exe"):
 print f.version


Nothing prints out.
Thank you,

Rob
rcjay272
 
Posts: 3
Joined: Tue Mar 19, 2013 5:50 pm


Return to General Discussions

Who is online

Users browsing this forum: Bing [Bot] and 2 guests