欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#判断某个软件是否已安装实现代码分享

程序员文章站 2022-06-14 17:26:14
private void button1_click(object sender, eventargs e) { if (checkadoberea...
private void button1_click(object sender, eventargs e)  
{  
  if (checkadobereader() == true)  
  {  
    messagebox.show("有安裝 adobe reader ");  
  }  
  else 
  {  
    messagebox.show("沒有安裝 adobe reader ");  
  }  
}  
/// <summary>  
/// 確認是否有安裝 adobe reader  
/// </summary>  
/// <returns>true: 有安裝, false:沒有安裝</returns>  
private bool checkadobereader()  
{  
  microsoft.win32.registrykey uninstallnode = microsoft.win32.registry.localmachine.opensubkey(@"software/microsoft/windows/currentversion/uninstall");  
  foreach (string subkeyname in uninstallnode.getsubkeynames())  
  {  
    microsoft.win32.registrykey subkey = uninstallnode.opensubkey(subkeyname);  
    object displayname = subkey.getvalue("displayname");  
    if (displayname != null)  
    {  
      if (displayname.tostring().contains("adobe reader"))  
      {  
        return true;  
        // messagebox.show(displayname.tostring());  
      }  
    }  
  }  
  return false;  
}