protected List<SoftwareDTOResponse> GetItemsFromRegistry(RegistryKey key, string path)
        {
            List<SoftwareDTOResponse> software = new List<SoftwareDTOResponse>();

            using (RegistryKey rk = key.OpenSubKey(path))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            SoftwareDTOResponse application = new SoftwareDTOResponse();
                            application.Label = sk.GetValue("DisplayName").ToString();
                            application.ModelName = application.Label;
                            application.Version = sk.GetValue("DisplayVersion").ToString();
                            application.Path = sk.GetValue("Publisher").ToString() +
                                               " - " +
                                               application.Label +
                                               " - " +
                                               application.Version;

                            software.Add(application);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            return software;
        }
Esempio n. 2
0
		public List<SoftwareDTOResponse> GetSoftwareInfo()
		{
			List<SoftwareDTOResponse> software = new List<SoftwareDTOResponse>();

			try
			{
				SelectQuery query = new SelectQuery(
					@"select Name, Vendor, Version 
					  from Win32_Product"
				);
				ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
				
				foreach (ManagementObject obj in searcher.Get())
				{
				    SoftwareDTOResponse soft = new SoftwareDTOResponse();
				    soft.Label = GetValueAsString(obj, "Name");
				    soft.Version = GetValueAsString(obj, "Version");
				    soft.Path = GetValueAsString(obj, "Vendor") +
				    			" - " +
				    			soft.Label +
				    			" - " +
				    			GetValueAsString(obj, "Version");
				    soft.ModelName = soft.Label;
				    
				    software.Add(soft);
				}
			}
			catch (ManagementException e)
			{
				Logger.Instance.LogError(e.ToString());
			}
			
			return software;
		}