Retrieving the installed softwares in WMI [modified]
-
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
-
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
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.
-
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
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 theWin32_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
-
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.
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
-
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 theWin32_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
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?
-
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?
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]