C# 查询注册表,判断本机是否安装Office2003,2007,2010,2013,2016和WPS

public void Check_OfficeAndWps()
{
    //是否安装Office
    bool isOfficeInstall = false;
    //是否安装Wps
    bool isWpsInstall = false;
    //Office版本
    int officeVersion = 0;

    //32位
    RegistryKey localMachine32 = Registry.LocalMachine;
    RegistryKey akey03 = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Excel\InstallRoot\");
    RegistryKey akey07 = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot\");
    RegistryKey akey10 = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot\");
    RegistryKey akey13 = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\Office\15.0\Excel\InstallRoot\");
    RegistryKey akey16 = localMachine32.OpenSubKey(@"SOFTWARE\Microsoft\Office\16.0\Excel\InstallRoot\");
    RegistryKey akeywps = localMachine32.OpenSubKey(@"SOFTWARE\Kingsoft\Office\6.0\common\");

    //64位
    RegistryKey localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
    if (akey03 == null)
        akey03 = localMachine64.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Excel\InstallRoot\");//查询2003
    if (akey07 == null)
        akey07 = localMachine64.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot\");//查询2007
    if (akey10 == null)
        akey10 = localMachine64.OpenSubKey(@"SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot\");//查询2010
    if (akey13 == null)
        akey13 = localMachine64.OpenSubKey(@"SOFTWARE\Microsoft\Office\15.0\Excel\InstallRoot\");//查询2013
    if (akey16 == null)
        akey16 = localMachine64.OpenSubKey(@"SOFTWARE\Microsoft\Office\16.0\Excel\InstallRoot\");//查询2016
    if (akeywps == null)
        akeywps = localMachine64.OpenSubKey(@"SOFTWARE\Kingsoft\Office\6.0\common\");//查询wps

    //检查本机是否安装Office2003
    if (akey03 != null)
    {
        string office03 = akey03.GetValue("Path").ToString();
        if (File.Exists(office03 + "Excel.exe"))
        {
            isOfficeInstall = true;
            officeVersion = 2003;
        }
    }

    //检查本机是否安装Office2007
    if (akey07 != null)
    {
        string office07 = akey07.GetValue("Path").ToString();
        if (File.Exists(office07 + "Excel.exe"))
        {
            isOfficeInstall = true;
            officeVersion = 2007;
        }
    }

    //检查本机是否安装Office2010
    if (akey10 != null)
    {
        string office10 = akey10.GetValue("Path").ToString();
        if (File.Exists(office10 + "Excel.exe"))
        {
            isOfficeInstall = true;
            officeVersion = 2010;
        }
    }

    //检查本机是否安装Office2013
    if (akey13 != null)
    {
        string office13 = akey13.GetValue("Path").ToString();
        if (File.Exists(office13 + "Excel.exe"))
        {
            isOfficeInstall = true;
            officeVersion = 2013;
        }
    }

    //检查本机是否安装Office2016       
    if (akey16 != null)
    {
        string office16 = akey16.GetValue("Path").ToString();
        if (File.Exists(office16 + "Excel.exe"))
        {
            isOfficeInstall = true;
            officeVersion = 2016;
        }
    }

    //检查本机是否安装wps
    if (akeywps != null)
    {
        string filewps = akeywps.GetValue("InstallRoot").ToString();
        if (File.Exists(filewps + @"\office6\et.exe"))
            isWpsInstall = true;
    }
}
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

钟一白

走过路过不要错过,赏一块是一块

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值