C#通过注册表检测是否安装Office和QQ等软件

C/S项目需求:

检测Office是否安装以及获取安装 路径 及安装版本

Copy to Clipboard

/// 检测是否安装office
///

/// 获得并返回安装的office版本 ///
public static bool IsInstallOffice(out string office_Version, out string office_Path)
{
bool result = false;
string str_OfficePath = string.Empty;
string str_OfficeVersion = string.Empty;
office_Version = string.Empty;
office_Path = string.Empty;

GetOfficePath(out str_OfficePath, out str_OfficeVersion);
if (!string.IsNullOrEmpty(str_OfficePath) && !string.IsNullOrEmpty(str_OfficeVersion))
{
result = true;
office_Version = str_OfficeVersion;
office_Path = str_OfficePath;
}
return result;
}

///

/// 获取并返回当前安装的office版本和安装路径
///

///office的安装路径 ///office的安装版本 private static void GetOfficePath(out string str_OfficePath, out string str_OfficeVersion)
{
string str_PatheResult = string.Empty;
string str_VersionResult = string.Empty;
string str_KeyName = “Path”;
object objResult = null;
Microsoft.Win32.RegistryValueKind regValueKind;//指定在注册表中存储值时所用的数据类型,或标识注册表中某个值的数据类型。
Microsoft.Win32.RegistryKey regKey = null;//表示 Windows 注册表中的项级节点(注册表对象
Microsoft.Win32.RegistryKey regSubKey = null;
try
{
regKey = Microsoft.Win32.Registry.LocalMachine;//读取HKEY_LOCAL_MACHINE项
if (regSubKey == null)
{//office97
regSubKey = regKey.OpenSubKey(@”SOFTWAREMicrosoftOffice8.0CommonInstallRoot”, false);//如果bool值为true则对打开的项进行读写操作,否则为只读打开
str_VersionResult = “Office97”;
str_KeyName = “OfficeBin”;
}
if (regSubKey == null)
{//Office2000
regSubKey = regKey.OpenSubKey(@”SOFTWAREMicrosoftOffice9.0CommonInstallRoot”, false);
str_VersionResult = “Pffice2000”;
str_KeyName = “Path”;
}
if (regSubKey == null)
{//officeXp
regSubKey = regKey.OpenSubKey(@”SOFTWAREMicrosoftOffice10.0CommonInstallRoot”, false);
str_VersionResult = “OfficeXP”;
str_KeyName = “Path”;
}

if (regSubKey == null)
{//Office2003
regSubKey = regKey.OpenSubKey(@”SOFTWAREMicrosoftOffice11.0CommonInstallRoot”, false);
str_VersionResult = “Office2003”;
str_KeyName = “Path”;
try
{
objResult = regSubKey.GetValue(str_KeyName);
regValueKind = regSubKey.GetValueKind(str_KeyName);
}
catch (Exception ex)
{
regSubKey = null;
}
}

if (regSubKey == null)
{//office2007
regSubKey = regKey.OpenSubKey(@”SOFTWAREMicrosoftOffice12.0CommonInstallRoot”, false);
str_VersionResult = “Office2007”;
str_KeyName = “Path”;
}
objResult = regSubKey.GetValue(str_KeyName);
regValueKind = regSubKey.GetValueKind(str_KeyName);
if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
{
str_PatheResult = objResult.ToString();
}
}
catch (Exception ex)
{
LogHelper.WriteLogError(ex.ToString());
//throw ex;
}
finally
{
if (regKey != null)
{
regKey.Close();
regKey = null;
}

if (regSubKey != null)
{
regSubKey.Close();
regSubKey = null;
}
}
str_OfficePath = str_PatheResult;
str_OfficeVersion = str_VersionResult;
}
#endregion

同理,检测QQ、Fetion、360杀毒、IE浏览器,Chrome、Office 2003/2007/2010

只需修改验证:

regSubKey = regKey.OpenSubKey(@”SOFTWARETencentPlatForm_Type_List3″, false);//如果bool值为true则对打开的项进行读写操作,否则为只读打开

即可

检测QQ是否已安装,通过注册表

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2015年9月6日
下一篇 2015年9月6日

相关推荐