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;
}
}
11-14
758
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-07
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交