I'm writing a program that needs to get the install date and version information of all the programs in a registry. I am able to get a list of all of the programs, but I do not know how to access any information about the programs themselves. If I was able to determine the filepath to where the files are located I would be able to access this information. I happen to know that the programs I'm interested in are all located in the C:\\Program Files (x86)\
folder, but they are in subfolders within this that I am unable to specify. Any ideas on how to get the filepaths of the files I am retrieving?
Here's my code:
public List<BSAApp> getInstalledApps( string computerName )
{
List<BSAApp> appList = new List<BSAApp>();
ManagementScope ms = new ManagementScope();
ms.Path.Server = computerName;
ms.Path.NamespacePath = "root\\cimv2";
ms.Options.EnablePrivileges = true;
ms.Connect();
ManagementClass mc = new ManagementClass( "StdRegProv" );
mc.Scope = ms;
ManagementBaseObject mbo;
mbo = mc.GetMethodParameters( "EnumKey" );
mbo.SetPropertyValue( "sSubKeyName", "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths" );
string[] subkeys = (string[])mc.InvokeMethod( "EnumKey", mbo, null ).Properties["sNames"].Value;
if( subkeys != null )
{
foreach( string strKey in subkeys )
{
string path = ?????
FileVersionInfo info = FileVersionInfo.GetVersionInfo( path );
appList.Add( new BSAApp( strKey, info.ProductVersion ) );
}
}
return appList;
}