コード例 #1
0
ファイル: MainForm.cs プロジェクト: Eroatlan/ProjetLinxya
        public void Run()
        {
            Ways wat = new Ways();
            softList = new SoftList();

            try
            {
                ManagementObjectSearcher searcher =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_Product");

                int i = 0;

                foreach (ManagementObject queryObj in searcher.Get())
                {
                    i++;
                    String idN = "";
                    String name = "";
                    String vend = "";
                    String instLoc = "";
                    String prodID = "";
                    String version = "";

                    try { idN = queryObj["IdentifyingNumber"].ToString(); }
                    catch (Exception) { }
                    try { name = queryObj["Name"].ToString(); }
                    catch (Exception) { }
                    try { vend = queryObj["Vendor"].ToString(); }
                    catch (Exception) { }
                    try { instLoc = queryObj["InstallLocation"].ToString(); }
                    catch (Exception) { }
                    try { prodID = queryObj["ProductID"].ToString(); }
                    catch (Exception) { }
                    try { version = queryObj["Version"].ToString(); }
                    catch (Exception) { }
                    if (name == "VMware Workstation" || name=="Microsoft Visual Studio Professional 2013")
                    {
                        Console.WriteLine(name+"   " + version);
                    }
                    softList.addSoft(new Software(idN, name, vend, instLoc, prodID, version));

                }
            }
            catch (ManagementException e)
            {
                MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
            }

            softList.firstTurn();

            foreach (Software s in softList.getList())
            {
                this.AddToListBoxSoftwares(s.toStringKey());
            }

            softList.secondTurn();

            foreach (Software s in softList.getList())
            {
                this.AddToListBoxSoftwares(s.toStringKey());
            }
        }