Can python find HW/SW installed on my PC - like Belarc?

Discussion in 'Python' started by walterbyrd, Apr 30, 2007.

  1. walterbyrd

    walterbyrd Guest

    Lets suppose, I want a listing of what hardware and software is
    installed on my
    windows box. Can I do that with Python?
     
    walterbyrd, Apr 30, 2007
    #1
    1. Advertisements

  2. walterbyrd

    Guest

    On Apr 30, 10:47 am, walterbyrd <> wrote:
    > Lets suppose, I want a listing of what hardware and software is
    > installed on my
    > windows box. Can I do that with Python?


    Yes, it is possible for Windows. I don't know how to grab the info for
    other OS's though. There is a caveat that is annoying. If the software
    doesn't put itself into the registry somehow, it is much harder to
    discover if it is indeed installed.

    For hardware, you'll need the WMI module and the win32 module. For the
    computer memory and the name of the PC, see below:

    c = wmi.WMI()
    for i in c.Win32_ComputerSystem():
    mem = int(i.TotalPhysicalMemory)
    compname = i.Name

    For the CPU:

    for i in c.Win32_Processor ():
    cputype = i.Name

    For other cool WMI tricks: http://tgolden.sc.sabren.com/python/wmi_cookbook.html

    For the majority of the software on your system, you'll want to
    iterate over the following registry key (and its subkeys) using the
    _winreg module and WMI's Registry() function:

    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

    Some code that worked for me (may need modification for your setup):

    from _winreg import HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey,
    EnumValue, QueryValueEx

    r = wmi.Registry ()
    result, names = r.EnumKey (hDefKey=HKEY_LOCAL_MACHINE,
    sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall")
    for subkey in names:
    try:
    appFile.write('++++++++++++++++++++++++++++++++++++++++++++++++
    +++++++++++++++++++++++++\n\n')
    key = OpenKey(HKEY_LOCAL_MACHINE,
    r"Software\Microsoft\Windows\CurrentVersion
    \Uninstall\%s" % subkey,0, KEY_ALL_ACCESS)
    try:
    temp = QueryValueEx(key, 'DisplayName')
    display = str(temp[0])
    appFile.write('Display Name: ' + display + '\nRegkey: ' +
    subkey + '\n')
    except:
    appFile.write('Regkey: ' + subkey + '\n')
    except:
    print 'Error opening key'

    # appFile is where I write the list to. You can just print to console.

    That should get you going.

    Mike
     
    , Apr 30, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Learner
    Replies:
    4
    Views:
    2,382
    Learner
    Jan 27, 2006
  2. Tristan Miller
    Replies:
    1
    Views:
    777
    Tristan Miller
    Jul 23, 2004
  3. Lou Pecora
    Replies:
    4
    Views:
    437
    Lou Pecora
    Nov 8, 2004
  4. python
    Replies:
    3
    Views:
    2,381
    Simon Brunning
    May 22, 2006
  5. Replies:
    3
    Views:
    681
    Jason
    Apr 28, 2008
  6. Chet Farmer

    Ruby can't find installed gems

    Chet Farmer, Aug 11, 2006, in forum: Ruby
    Replies:
    3
    Views:
    212
    Chet Farmer
    Aug 12, 2006
  7. Zhao Yi
    Replies:
    3
    Views:
    211
    Rob Biedenharn
    Jan 6, 2009
  8. MaggotChild
    Replies:
    1
    Views:
    320
    MaggotChild
    Oct 28, 2009
Loading...