0

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;
        }

1 Answers1

2
ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM  Win32_Product");
foreach(ManagementObject mo in mos.Get())
{
  Console.WriteLine(mo["Name"]);
  Console.WriteLine(mo["InstallState"]);
}

Get installed applications in a system

But as mentioned in that thread, it has its own drawbacks.

Community
  • 1
  • 1
roymustang86
  • 8,054
  • 22
  • 70
  • 101
  • Yes, half of the programs I am searching for were not installed with MIS so they are not found there. –  Jul 09 '12 at 20:49
  • Hey, so how did you do it? Or, are you still having this problem? – roymustang86 Jul 12 '12 at 20:02
  • I was able to retrieve some of the need programs using the method above, and had to settle for just the names of the other programs using the method in my question. –  Jul 12 '12 at 20:53