Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Retrieving the installed softwares in WMI [modified]

Retrieving the installed softwares in WMI [modified]

Scheduled Pinned Locked Moved C#
helpquestionannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toink toink
    wrote on last edited by
    #1

    Hi! How do we retrieve all the installed softwares in WMI? All means all the softwares being installed in the computer. I used win32_Product yet it only retrieves those microsoft softwares and it even displays everything added to that software like an update. The following are the needed information: Softwarename InstallDate SotwarePath AllotedLocationType RegistryPath ExecutableFilename LastUsed TotalUsageDurationMins IsUninstalled IsHotfix IsServicePack isUnauthorized Please help. Thanks. -- modified at 7:18 Thursday 16th August, 2007

    H S 2 Replies Last reply
    0
    • T toink toink

      Hi! How do we retrieve all the installed softwares in WMI? All means all the softwares being installed in the computer. I used win32_Product yet it only retrieves those microsoft softwares and it even displays everything added to that software like an update. The following are the needed information: Softwarename InstallDate SotwarePath AllotedLocationType RegistryPath ExecutableFilename LastUsed TotalUsageDurationMins IsUninstalled IsHotfix IsServicePack isUnauthorized Please help. Thanks. -- modified at 7:18 Thursday 16th August, 2007

      H Offline
      H Offline
      Harkamal Singh
      wrote on last edited by
      #2

      You can enumerate keys for path... HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall ..and then look for DisplayName, UninstallString and other values as suited. If you get to know a better way out please do let me know as well :) Cheers H.

      S 1 Reply Last reply
      0
      • T toink toink

        Hi! How do we retrieve all the installed softwares in WMI? All means all the softwares being installed in the computer. I used win32_Product yet it only retrieves those microsoft softwares and it even displays everything added to that software like an update. The following are the needed information: Softwarename InstallDate SotwarePath AllotedLocationType RegistryPath ExecutableFilename LastUsed TotalUsageDurationMins IsUninstalled IsHotfix IsServicePack isUnauthorized Please help. Thanks. -- modified at 7:18 Thursday 16th August, 2007

        S Offline
        S Offline
        Scott Dorman
        wrote on last edited by
        #3

        Using WMI isn't the simplest thing to do from managed code. If you search Google, you'll find a lot of information. Here is sample code from a message[^] in the microsft.public.dotnet.framework.wmi newsgroup:

        const uint HKEY_LOCAL_MACHINE = unchecked((uint)0x80000002);
        ManagementClass wmiRegistry = new ManagementClass("root/default", "StdRegProv", null);

        //Enumerate subkeys
        string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        object[] methodArgs = new object[] {HKEY_LOCAL_MACHINE, keyPath, null};
        uint returnValue = (uint)wmiRegistry.InvokeMethod("EnumKey", methodArgs);
        Console.WriteLine("Executing EnumKey() returns: {0}", returnValue);

        if (null != methodArgs[2])
        {
        string[] subKeys = methodArgs[2] as String[];

        if (subKeys == null) return;

        ManagementBaseObject inParam = wmiRegistry.GetMethodParameters("GetStringValue");
        inParam["hDefKey"] = HKEY_LOCAL_MACHINE;
        string keyName = "";

        foreach(string subKey in subKeys)
        {
        //Display application name
        keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subKey;
        keyName = "DisplayName";
        inParam["sSubKeyName"] = keyPath;
        inParam["sValueName"] = keyName;
        ManagementBaseObject outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);

          if ((uint)outParam\["ReturnValue"\] == 0)
             Console.WriteLine(outParam\["sValue"\]);
        

        }
        }

        This is essentially just enumerating over the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ registry key, so you can use the normal .NET registry classes to do the same thing without WMI. Using the Win32_Product class, you would want to do something like this:

        ManagementObjectSearcher products = new ManagementObjectSearcher("SELECT * FROM Win32_Product");

        foreach (ManagementObject product in products.Get())
        {
        Console.WriteLine("Software name: {0}", product.Name);
        Console.WriteLine("Install date: {0}", product.InstallDate);
        ...
        }

        The properties you list aren't all included in the Win32_Product[^] class, so you will probably need to do additional queries against other obje

        T 1 Reply Last reply
        0
        • H Harkamal Singh

          You can enumerate keys for path... HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall ..and then look for DisplayName, UninstallString and other values as suited. If you get to know a better way out please do let me know as well :) Cheers H.

          S Offline
          S Offline
          Scott Dorman
          wrote on last edited by
          #4

          Have a look at my response[^]. At the bottom of it is the WMI query against the Win32_Product class that you can use, it's much simpler than enumerating over the registry keys.

          ----------------------------- In just two days, tomorrow will be yesterday. http://geekswithblogs.net/sdorman

          1 Reply Last reply
          0
          • S Scott Dorman

            Using WMI isn't the simplest thing to do from managed code. If you search Google, you'll find a lot of information. Here is sample code from a message[^] in the microsft.public.dotnet.framework.wmi newsgroup:

            const uint HKEY_LOCAL_MACHINE = unchecked((uint)0x80000002);
            ManagementClass wmiRegistry = new ManagementClass("root/default", "StdRegProv", null);

            //Enumerate subkeys
            string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            object[] methodArgs = new object[] {HKEY_LOCAL_MACHINE, keyPath, null};
            uint returnValue = (uint)wmiRegistry.InvokeMethod("EnumKey", methodArgs);
            Console.WriteLine("Executing EnumKey() returns: {0}", returnValue);

            if (null != methodArgs[2])
            {
            string[] subKeys = methodArgs[2] as String[];

            if (subKeys == null) return;

            ManagementBaseObject inParam = wmiRegistry.GetMethodParameters("GetStringValue");
            inParam["hDefKey"] = HKEY_LOCAL_MACHINE;
            string keyName = "";

            foreach(string subKey in subKeys)
            {
            //Display application name
            keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + subKey;
            keyName = "DisplayName";
            inParam["sSubKeyName"] = keyPath;
            inParam["sValueName"] = keyName;
            ManagementBaseObject outParam = wmiRegistry.InvokeMethod("GetStringValue", inParam, null);

              if ((uint)outParam\["ReturnValue"\] == 0)
                 Console.WriteLine(outParam\["sValue"\]);
            

            }
            }

            This is essentially just enumerating over the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ registry key, so you can use the normal .NET registry classes to do the same thing without WMI. Using the Win32_Product class, you would want to do something like this:

            ManagementObjectSearcher products = new ManagementObjectSearcher("SELECT * FROM Win32_Product");

            foreach (ManagementObject product in products.Get())
            {
            Console.WriteLine("Software name: {0}", product.Name);
            Console.WriteLine("Install date: {0}", product.InstallDate);
            ...
            }

            The properties you list aren't all included in the Win32_Product[^] class, so you will probably need to do additional queries against other obje

            T Offline
            T Offline
            toink toink
            wrote on last edited by
            #5

            how about if we will display the installdate and installlocation using the latter code? or using the registry? if inParam["sValueName"] = keyName is used to get the Displayname, how about the rest of the values? like installdate, softwarepath and the rest of the values?

            S 1 Reply Last reply
            0
            • T toink toink

              how about if we will display the installdate and installlocation using the latter code? or using the registry? if inParam["sValueName"] = keyName is used to get the Displayname, how about the rest of the values? like installdate, softwarepath and the rest of the values?

              S Offline
              S Offline
              Scott Dorman
              wrote on last edited by
              #6

              toink toink wrote:

              how about if we will display the installdate and installlocation using the latter code? or using the registry?

              What code are you referring to here?

              toink toink wrote:

              if inParam["sValueName"] = keyName is used to get the Displayname, how about the rest of the values? like installdate, softwarepath and the rest of the values?

              It sounds like you would probably do better to use this

              ManagementObjectSearcher products = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
              foreach (ManagementObject product in products.Get())
              {
              Console.WriteLine("Software name: {0}", product.Name);
              Console.WriteLine("Install date: {0}", product.InstallDate);
              ...
              }

              Scott.


              —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups