公司的IT工程师某一天找我聊天,说有没有一个程序能够统计电脑上安装的软件,公司采用的是域控,然后把这个软件放在域控的组策略里面,设置一番,只要登录域控的时候自动运行一遍,然后把采集的信息写入共享目录,这样就不用一台一台的统计了。
当时一想就直接用C#写了一个控制台程序。代码如下:

static void Main(string[] args)
        {
            string path = @"\\192.168.10.251\\hard_info\\";
            StringBuilder proinfo = new StringBuilder();
            string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
            {
                foreach (string skName in rk.GetSubKeyNames())
                {
                    using (RegistryKey sk = rk.OpenSubKey(skName))
                    {
                        try
                        {
                            var displayName = sk.GetValue("DisplayName");
                            if (displayName != null)
                            {
                                proinfo.AppendLine(displayName.ToString());
                            }
                        }
                        catch 
                        {
                        }
                    }
                }
            }
            File.WriteAllText(path + Dns.GetHostName() + ".txt", proinfo.ToString());
            Environment.Exit(0);
        }
View Code

相关文章:

  • 2021-11-03
  • 2021-05-15
  • 2021-10-04
  • 2021-09-30
  • 2021-07-20
  • 2021-09-22
  • 2021-04-17
  • 2021-05-08
猜你喜欢
  • 2022-02-10
  • 2022-12-23
  • 2021-08-14
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案