using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace solarApp
{
    public partial class fmTest : Form
    {
        public fmTest()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IsProgramInstalled("") ;
        }

        public  bool IsProgramInstalled(string programDisplayName)
        {

            Console.WriteLine(string.Format("Checking install status of: {0}", programDisplayName));
            foreach (var item in Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall").GetSubKeyNames())
            {

                object programName = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + item).GetValue("DisplayName");

                //Console.WriteLine(programName);
                //if (!string.IsNullOrEmpty(programName.ToString()))
                if (!(programName == null))
                {
                    richTextBox1.AppendText(programName.ToString() + Environment.NewLine);
                    if (string.Equals(programName, programDisplayName))
                    {
                        Console.WriteLine("Install status: INSTALLED");
                        return true;
                    }
                } 
            }
            Console.WriteLine("Install status: NOT INSTALLED");
            return false;
        }
    }
}
