安装或卸载软件时如何获得消息 [英] How to get a message when a software is installed or uninstalled

查看:63
本文介绍了安装或卸载软件时如何获得消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai ALL,

每当安装新软件或卸载任何软件时,我都会收到一条消息.如何使用C#执行此操作.通过C#帮助我.

Hai ALL,

I would to get a message whenever a new software is installed or any software is uninstalled. How to do this using C#. Help me through C#.

推荐答案


下面的代码显示了当前已安装软件的列表,所以我要做的是,创建xml记录,创建一个函数以获取用于同步的新列表,获取不匹配&&终于找到受害者了.
Hi,
The code below display the list of current installed software, so what I would do is, make a xml record, create a function to get new list for synchronization, get the mismatch && finally detect the victim.
string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
    foreach(string subkey_name in key.GetSubKeyNames())
    {
        using(RegistryKey subkey = key.OpenSubKey(subkey_name))
        {
                Console.WriteLine(subkey.GetValue("DisplayName"));
        }
    }
}

//Another way to do that:

ManagementObjectSearcher managementObjects = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
foreach(ManagementObject managementObject in managementObjects.Get())
{
    Console.WriteLine(mo["Name"]);
}


这篇关于安装或卸载软件时如何获得消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆