Exemple #1
0
        void GetDataFromReg(string firstKey, string extendKey, int searIdx)
        {
            List <ProgramsData> tmpLst = new List <ProgramsData>();
            ProgramsData        pgData = null;
            object regObj;

            RegistryKey rk = null;

            System.Text.RegularExpressions.Match mt;
            switch (searIdx)
            {
            case 0:
                rk = Registry.LocalMachine.OpenSubKey(firstKey);
                break;

            case 1:
                rk = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(firstKey);
                break;

            default:
                return;
            }

            foreach (string skName in rk.GetSubKeyNames())
            {
                using (RegistryKey sk = rk.OpenSubKey(skName))
                {
                    if (sk == null)
                    {
                        continue;
                    }
                    pgData = new ProgramsData();

                    regObj = sk.GetValue(pgProperity[0]);
                    if (regObj != null)
                    {
                        pgData.DisplayName = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[1]);
                    if (regObj != null)
                    {
                        pgData.DisplayVersion = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[2]);
                    if (regObj != null)
                    {
                        pgData.Publisher = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[3]);
                    if (regObj != null)
                    {
                        pgData.Version = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[4]);
                    if (regObj != null)
                    {
                        pgData.InstallDate = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[5]);
                    if (regObj != null)
                    {
                        pgData.InstallLocation = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[6]);
                    if (regObj != null)
                    {
                        pgData.InstallSource = regObj.ToString();
                    }
                    regObj = sk.GetValue(pgProperity[7]);
                    if (regObj != null)
                    {
                        string iconPath = regObj.ToString(), strPat = @"([C|c][ -\{\}\w\\:]+.exe)([\W\w]*)";

                        if (!string.IsNullOrEmpty(iconPath))
                        {
                            mt = System.Text.RegularExpressions.Regex.Match(iconPath, strPat);
                            if (mt.Success && System.IO.File.Exists(mt.Groups[1].Value))
                            {
                                pgData.DisplayIcon = IconToImageSource(System.Drawing.Icon.ExtractAssociatedIcon(mt.Groups[1].Value));
                                if (string.IsNullOrEmpty(pgData.InstallLocation))
                                {
                                    FileInfo fi = new FileInfo(mt.Groups[1].Value);
                                    pgData.InstallLocation = fi.Directory.FullName;
                                }
                                //pgList.Add(pgData);
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(pgData.DisplayName))
                {
                    if (null == tmpLst.Find(x => x.DisplayName.Equals(pgData.DisplayName) && x.DisplayVersion.Equals(pgData.DisplayVersion)))
                    {
                        tmpLst.Add(pgData);
                    }
                    //pgList.Add(pgData);
                }
            }

            foreach (ProgramsData sPgData in tmpLst)
            {
                pgList.Add(sPgData);
            }
        }
Exemple #2
0
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            switch (btn.Name)
            {
            case "btnGetList":
                GetProgramsList();
                break;

            case "btnSetLink":
                ProgramsData pgData = dgPrograms.SelectedItem as ProgramsData;
                if (pgData != null && !string.IsNullOrEmpty(pgData.InstallLocation))
                {
                    // Create OpenFileDialog
                    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                    dlg.InitialDirectory = pgData.InstallLocation;
                    // Set filter for file extension and default file extension
                    dlg.DefaultExt = ".exe";
                    //dlg.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";
                    dlg.Filter = "Exe File (*.exe)|*.exe|All Files (*.*)|*.*";


                    // Display OpenFileDialog by calling ShowDialog method
                    Nullable <bool> result = dlg.ShowDialog();


                    // Get the selected file name and display in a TextBox
                    if (result == true)
                    {
                        // Open document
                        FileInfo fi = new FileInfo(dlg.FileName);
                        strLinkProcName = Path.GetFileNameWithoutExtension(fi.Name);
                        //textBox1.Text = filename;
                    }
                }
                break;

            case "btnStartMonitor":
                if (!isChecking)
                {
                    if (string.IsNullOrEmpty(strLinkProcName))
                    {
                        MessageBox.Show("Plsase Setup Link first!!");
                    }
                    else
                    {
                        isCheckLink             = true;
                        btnStartMonitor.Content = "STOP Monitor";
                        isChecking           = !isChecking;
                        thCheckProc          = new Thread(CheckLinkProcess);
                        thCheckProc.Priority = ThreadPriority.Normal;
                        thCheckProc.Start();
                    }
                }
                else
                {
                    isCheckLink             = false;
                    btnStartMonitor.Content = "Start Monitor";
                    isChecking = !isChecking;

                    //thCheckProc.Abort();
                }
                break;

            case "btnDismiss":
                MaskofMonitor.Visibility = Visibility.Collapsed;
                break;
            }
        }