在我的Windows应用程序中,我想检查运行该应用程序的机器上是否安装了firefox。我可以吗? [英] In my windows application I want to check whether firefox is installed or not on machine running that application.how can I?

查看:78
本文介绍了在我的Windows应用程序中,我想检查运行该应用程序的机器上是否安装了firefox。我可以吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些安全性和权限问题,我无法读取注册表,并且通过WMI类我获得了通过msi安装的应用程序列表。有没有办法检查firefox是否安装在syatem中而不读取注册表项? br />
我还想以编程方式运行一些命令在Firefox中安装插件。

我在这个程序列表中试过这个我没有得到Mozilla Firefox。



我的尝试:



I cannot read registry due to some security and permission problem and through WMI class i am getting list of applications which are installed through msi.Is there any way to check whether firefox is installed in syatem or not without reading registry key?
Also i want to run some commands programmatically to install addons in Firefox.
I have tried this in this list of programmes I am not getting Mozilla Firefox.

What I have tried:

public static string GetFireFox()
     {
         string name = String.Empty;

         try
         {
             List<string> programmes = new List<string>();
             ManagementObjectSearcher objMOS = new ManagementObjectSearcher("Select * FROM Win32_Product");
             ManagementObjectCollection objMOC = objMOS.Get();

             foreach (ManagementObject objMO in objMOC)
             {
                 object tempMacAddrObj = objMO["Name"];

                 if (tempMacAddrObj == null)
                 {
                     continue;
                 }

                     name = tempMacAddrObj.ToString();
                     programmes.Add(name);


                 objMO.Dispose();

             }

             name = name.Replace(":", "");

             return name;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Programme");
             return name;
         }
     }

推荐答案

请看这里:获取已安装的浏览器和版本C#| Robb Sadler的博客 [ ^ ] - 它从teh注册表中收集已安装的浏览器。
See here: Getting Installed Browsers and Version C# | Robb Sadler's Weblog[^] - it collects installed browsers from teh registry.


要在您的应用程序中导入它,请使用此





To import it in your application use this


foreach (Browser browser in GetBrowsers())
{
Console.WriteLine(string.Format("{0}: \n\tPath: {1} \n\tVersion: {2} \n\tIcon: {3}", browser.Name, browser.Path, browser.Version, browser.IconPath));
}
Console.ReadKey();
}




public static List<Browser> GetBrowsers()
{
RegistryKey browserKeys;
//on 64bit the browsers are in a different location
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
if (browserKeys == null)
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
string[] browserNames = browserKeys.GetSubKeyNames();
var browsers = new List<Browser>();
for (int i = 0; i < browserNames.Length; i++)
{
Browser browser = new Browser();
RegistryKey browserKey = browserKeys.OpenSubKey(browserNames[i]);
browser.Name = (string)browserKey.GetValue(null);
RegistryKey browserKeyPath = browserKey.OpenSubKey(@"shell\open\command");
browser.Path = (string)browserKeyPath.GetValue(null).ToString().StripQuotes();
RegistryKey browserIconPath = browserKey.OpenSubKey(@"DefaultIcon");
browser.IconPath = (string)browserIconPath.GetValue(null).ToString().StripQuotes();
browsers.Add(browser);
if (browser.Path != null)
browser.Version = FileVersionInfo.GetVersionInfo(browser.Path).FileVersion;
else
browser.Version = "unknown";
}
return browsers;
}
}


internal static class Extensions
{
///
/// if string begins and ends with quotes, they are removed
///
internal static String StripQuotes(this String s)
{
if (s.EndsWith("\"") && s.StartsWith("\""))
{
return s.Substring(1, s.Length - 2);
}
else
{
return s;
}
}
}


class Browser
{
public string Name { get; set; }
public string Path { get; set; }
public string IconPath { get; set; }
public string Version { get; set; }
}
}


这篇关于在我的Windows应用程序中,我想检查运行该应用程序的机器上是否安装了firefox。我可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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