ソースを参照

添加控制面板安装的程序列表及详细信息

yuzhengyang 8 年 前
コミット
f772f33caf

+ 4 - 3
Fork.Net/Test/Y.Test/Views/TestComputerInfoForm.Designer.cs

@@ -33,18 +33,19 @@
             // 
             // 
             // textBox1
             // textBox1
             // 
             // 
-            this.textBox1.Location = new System.Drawing.Point(13, 13);
+            this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.textBox1.Location = new System.Drawing.Point(0, 0);
             this.textBox1.Multiline = true;
             this.textBox1.Multiline = true;
             this.textBox1.Name = "textBox1";
             this.textBox1.Name = "textBox1";
             this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
             this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
-            this.textBox1.Size = new System.Drawing.Size(560, 400);
+            this.textBox1.Size = new System.Drawing.Size(835, 453);
             this.textBox1.TabIndex = 0;
             this.textBox1.TabIndex = 0;
             // 
             // 
             // TestComputerInfoForm
             // TestComputerInfoForm
             // 
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(585, 425);
+            this.ClientSize = new System.Drawing.Size(835, 453);
             this.Controls.Add(this.textBox1);
             this.Controls.Add(this.textBox1);
             this.Name = "TestComputerInfoForm";
             this.Name = "TestComputerInfoForm";
             this.Text = "TestComputerInfoForm";
             this.Text = "TestComputerInfoForm";

+ 14 - 36
Fork.Net/Test/Y.Test/Views/TestComputerInfoForm.cs

@@ -7,6 +7,9 @@ using System.Drawing;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 using System.Windows.Forms;
 using System.Windows.Forms;
+using Y.Utils.DataUtils.Collections;
+using Y.Utils.DataUtils.UnitConvertUtils;
+using Y.Utils.SoftwareUtils;
 using Y.Utils.WindowsUtils.InfoUtils;
 using Y.Utils.WindowsUtils.InfoUtils;
 
 
 namespace Y.Test.Views
 namespace Y.Test.Views
@@ -19,6 +22,17 @@ namespace Y.Test.Views
         }
         }
         private void TestComputerInfoForm_Load(object sender, EventArgs e)
         private void TestComputerInfoForm_Load(object sender, EventArgs e)
         {
         {
+            var softwareinfos = Utils.SoftwareUtils.SoftwareTool.GetControlList();
+            if (ListTool.HasElements(softwareinfos))
+            {
+                softwareinfos.ForEach(x =>
+                {
+                    if (x.Name != "")
+                        Print(string.Format("{0} / 【{1}】 / {2} / {3} 【{4}】",
+                            x.Name, x.InstallDate, x.Publisher, x.Version,
+                            ByteConvertTool.Fmt(x.EstimatedSize * 1024)));
+                });
+            }
         }
         }
         private void Print(string s)
         private void Print(string s)
         {
         {
@@ -56,41 +70,5 @@ namespace Y.Test.Views
             Print("主板 制造商 " + boardinfo.Item1 + " 型号 " + boardinfo.Item2 + " 序列号 " + boardinfo.Item3);
             Print("主板 制造商 " + boardinfo.Item1 + " 型号 " + boardinfo.Item2 + " 序列号 " + boardinfo.Item3);
         }
         }
 
 
-        private void GetSoftInfo()
-        {
-            string temp = null, tempType = null;
-            object displayName = null, uninstallString = null, releaseType = null;
-            RegistryKey currentKey = null;
-            int softNum = 0;
-            RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");//获取指定路径下的键
-            try
-            {
-                foreach (string item in pregkey.GetSubKeyNames())               //循环所有子键
-                {
-                    currentKey = pregkey.OpenSubKey(item);
-                    displayName = currentKey.GetValue("DisplayName");           //获取显示名称
-                    uninstallString = currentKey.GetValue("UninstallString");   //获取卸载字符串路径
-                    releaseType = currentKey.GetValue("ReleaseType");           //发行类型,值是Security Update为安全更新,Update为更新
-                    bool isSecurityUpdate = false;
-                    if (releaseType != null)
-                    {
-                        tempType = releaseType.ToString();
-                        if (tempType == "Security Update" || tempType == "Update")
-                            isSecurityUpdate = true;
-                    }
-                    if (!isSecurityUpdate && displayName != null && uninstallString != null)
-                    {
-                        softNum++;
-                        temp += displayName.ToString() + Environment.NewLine;
-                    }
-                }
-            }
-            catch (Exception E)
-            {
-                MessageBox.Show(E.Message.ToString());
-            }
-            richTextBox1.Text = "您本机安装了" + softNum.ToString() + "个" + Environment.NewLine + temp;
-            pregkey.Close();
-        }
     }
     }
 }
 }

+ 1 - 1
Fork.Net/Y.Utils/SoftwareUtils/SoftwareModel.cs

@@ -5,7 +5,7 @@ using System.Text;
 
 
 namespace Y.Utils.SoftwareUtils
 namespace Y.Utils.SoftwareUtils
 {
 {
-    public class SoftwareModel
+    public class SoftwareInfo
     {
     {
         public string Name { get; set; }
         public string Name { get; set; }
         public string Version { get; set; }
         public string Version { get; set; }

+ 26 - 10
Fork.Net/Y.Utils/SoftwareUtils/SoftwareTool.cs

@@ -18,7 +18,7 @@ namespace Y.Utils.SoftwareUtils
         /// <returns></returns>
         /// <returns></returns>
         public static bool ExistControl(string name)
         public static bool ExistControl(string name)
         {
         {
-            if (GetControlList().Contains(name))
+            if (GetControlList().Any(x => x.Name == name))
                 return true;
                 return true;
             return false;
             return false;
         }
         }
@@ -35,18 +35,18 @@ namespace Y.Utils.SoftwareUtils
             }
             }
             return flag;
             return flag;
         }
         }
-        public static List<string> GetControlList()
+        public static List<SoftwareInfo> GetControlList()
         {
         {
-            List<string> result = new List<string>();
+            List<SoftwareInfo> result = new List<SoftwareInfo>();
             result.AddRange(GetControlList(Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.LocalMachine.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.CurrentUser.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             result.AddRange(GetControlList(Registry.CurrentUser.OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall")));
             return result;
             return result;
         }
         }
-        private static List<string> GetControlList(RegistryKey key)
+        private static List<SoftwareInfo> GetControlList(RegistryKey key)
         {
         {
-            List<string> result = new List<string>();
+            List<SoftwareInfo> result = new List<SoftwareInfo>();
             try
             try
             {
             {
                 if (key != null)//如果系统禁止访问则返回null
                 if (key != null)//如果系统禁止访问则返回null
@@ -57,12 +57,28 @@ namespace Y.Utils.SoftwareUtils
                         RegistryKey SubKey = key.OpenSubKey(SubKeyName);
                         RegistryKey SubKey = key.OpenSubKey(SubKeyName);
                         if (SubKey != null)
                         if (SubKey != null)
                         {
                         {
-                            String SoftwareName = SubKey.GetValue("DisplayName", "Nothing").ToString();
-                            //如果没有取到,则不存入动态数组
-                            if (SoftwareName != "Nothing")
+
+                            string name = SubKey.GetValue("DisplayName", "").ToString();
+                            string pub = SubKey.GetValue("Publisher", "").ToString();
+                            string version = SubKey.GetValue("DisplayVersion", "").ToString();
+                            string datestr = SubKey.GetValue("InstallDate", "").ToString();
+                            string sizestr = SubKey.GetValue("EstimatedSize", "").ToString();
+                            string helpurl = SubKey.GetValue("HelpLink", "").ToString();
+                            string abouturl = SubKey.GetValue("URLInfoAbout", "").ToString();
+                            DateTime date;
+                            DateTime.TryParseExact(datestr, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out date);
+                            int size = 0;
+                            int.TryParse(sizestr, out size);
+                            result.Add(new SoftwareInfo()
                             {
                             {
-                                result.Add(SoftwareName.Trim());
-                            }
+                                Name = name,
+                                Publisher = pub,
+                                Version = version,
+                                InstallDate = date,
+                                EstimatedSize = size,
+                                HelpLink = helpurl,
+                                URLInfoAbout = abouturl,
+                            });
                         }
                         }
                         SubKey?.Close();
                         SubKey?.Close();
                     }
                     }

+ 1 - 1
Fork.Net/Y.Utils/Y.Utils.csproj

@@ -86,7 +86,7 @@
     <Compile Include="IOUtils\PathUtils\DirTool.cs" />
     <Compile Include="IOUtils\PathUtils\DirTool.cs" />
     <Compile Include="IOUtils\FileUtils\FileCodeTool.cs" />
     <Compile Include="IOUtils\FileUtils\FileCodeTool.cs" />
     <Compile Include="IOUtils\FileUtils\FileTool.cs" />
     <Compile Include="IOUtils\FileUtils\FileTool.cs" />
-    <Compile Include="SoftwareUtils\SoftwareModel.cs" />
+    <Compile Include="SoftwareUtils\SoftwareInfo.cs" />
     <Compile Include="SoftwareUtils\SoftwareTool.cs" />
     <Compile Include="SoftwareUtils\SoftwareTool.cs" />
     <Compile Include="WindowsUtils\APIUtils\FormStyleAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\FormStyleAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\PermissionAPI.cs" />
     <Compile Include="WindowsUtils\APIUtils\PermissionAPI.cs" />