如果通过自动化判断浏览器是否安装,安装位置在哪里?
读取本地注册表
这里以谷歌浏览器作为示范,同样可以用于其他程序【例如火狐浏览器】,但不是所有的,原因可能与安装位置或者写入注册表位置有关
using System;
using Microsoft.Win32;
try{
string app = "chrome.exe";
RegistryKey regKey = Registry.LocalMachine;
RegistryKey regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + app, false);
string strKey = string.Empty;
object objResult = regSubKey.GetValue(strKey);
RegistryValueKind regValueKind = regSubKey.GetValueKind(strKey);
if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
{
string path = objResult.ToString();
}
}
catch{
Console.WriteLine("尚未安装谷歌浏览器");
}
其他方案
在谷歌浏览器快捷方式上面,右键选择属性,查看目标里面的地址
不过这种方式不太适合自动化处理