views:

6423

answers:

5

When I say "installed application", I basically mean any application visible in [Control Panel]->[Add/Remove Programs].

I would prefer to do it in Python, but C or C++ is also fine.

+7  A: 

Check out the Win32_Product WMI (Windows Management Instrumentation) class. Here's a tutorial on using WMI in Python.

DrJokepu
I second this. Getting used to the WMI will help you with other windows admin related tasks. I recently wrote a sample for how to use the WMI from C++. http://blog.emptycrate.com/node/376
lefticus
There are some caveats, though. WMI can be disabled on some PCs. Also, it does not list all the applications visible in the Control Panel applet -- only those installed by a compliant installer.
atzz
+6  A: 

If you mean the list of installed applications that is shown in Add\Remove Programs in the control panel, you can find it in the registry key:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

more info about how the registry tree is structured can be found here.

You need to use the winreg API in python to read the values from the registry.

Aziz
Dang. you beat me to it.
Daniel A. White
THat key is empty on my system. Check the OS lsiting at the bottom of your link and you'll see it's not for WinXP.
sharkin
@R.A, this registry key contains a lot of sub-keys (sub folders). Each represent a program in the uninstall list. Please read about the structure of that key in the mentioned link.
Aziz
Yes, I'm sorry, I find them in that regkey actually, my system froze for a while and I made a fast judegement since the link you gave didn't mention XP. Guess the article's just old.
sharkin
It's used in both XP and Vista: http://www.vistax64.com/attachments/tutorials/7151d1223671005-programs-features-remove-uninstall-entry-32bit_reg.jpg
Aziz
That knowledge base article lists older versions of the OS. It might or might not work in newer versions. Unless you can find it documented in the MSDN library, you probably shouldn't rely on it. I'd look at WMI as suggested by other answers.
Adrian McCarthy
+6  A: 

Control Panel uses Win32 COM api, which is the official method (see Google Groups, Win32)
Never rely on registry.

+1 for "never rely on the registry"
Rob
+4  A: 

The Microsoft Script Repository has a script for listing all installed software.

import win32com.client
strComputer = "."
objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator")
objSWbemServices = objWMIService.ConnectServer(strComputer,"root\cimv2")
colItems = objSWbemServices.ExecQuery("Select * from Win32_Product")
for objItem in colItems:
    print "Caption: ", objItem.Caption
    print "Description: ", objItem.Description
    print "Identifying Number: ", objItem.IdentifyingNumber
    print "Install Date: ", objItem.InstallDate
    print "Install Date 2: ", objItem.InstallDate2
    print "Install Location: ", objItem.InstallLocation
    print "Install State: ", objItem.InstallState
    print "Name: ", objItem.Name
    print "Package Cache: ", objItem.PackageCache
    print "SKU Number: ", objItem.SKUNumber
    print "Vendor: ", objItem.Vendor
    print "Version: ", objItem.Version
John Fouhy
A: 

C#.net code for getting the list of installed software using WMI in xp and win7(wmi is the only way in win7)

    WqlObjectQuery wqlQuery =
      new WqlObjectQuery("SELECT * FROM Win32_Product");
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(wqlQuery);

        foreach (ManagementObject software in searcher.Get()) {
            Console.WriteLine(software["Caption"]);
        }