怎么C#获取office 的版本区分出是office 2003还是office 2007 我想通过程序获得office的版本,请问哪位大哥会,给段代码呗!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 获取当前某个版本Office的安装路径 /// </summary> /// <param name="Path">返回当前系统Office安装路径</param> /// <param name="Version">返回当前系统Office版本信息</param> public static void GetOfficePath(out string Path,out string Version) { string strPathResult = ""; string strVersionResult = ""; string strKeyName = "Path"; object objResult = null; Microsoft.Win32.RegistryValueKind regValueKind; Microsoft.Win32.RegistryKey regKey = null; Microsoft.Win32.RegistryKey regSubKey = null; try { regKey = Microsoft.Win32.Registry.LocalMachine; if (regSubKey == null) {//office97 regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\8.0\Common\InstallRoot", false); strVersionResult = "office97"; strKeyName = "OfficeBin"; } if (regSubKey == null) {//Office2000 regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\9.0\Common\InstallRoot", false); strVersionResult = "office2000"; strKeyName = "Path"; } if (regSubKey == null) {//officeXp regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", false); strVersionResult = "officeXP"; strKeyName = "Path"; } if (regSubKey == null) {//Office2003 regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", false); strVersionResult = "office2003"; strKeyName = "Path"; } if (regSubKey == null) {//office2007 regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Common\InstallRoot", false); strVersionResult = "office2007"; strKeyName = "Path"; } objResult = regSubKey.GetValue(strKeyName); regValueKind = regSubKey.GetValueKind(strKeyName); if (regValueKind == Microsoft.Win32.RegistryValueKind.String) { strPathResult = objResult.ToString(); } } catch (System.Security.SecurityException ex) { throw new System.Security.SecurityException("您没有读取注册表的权限", ex); } catch (Exception ex) { throw new Exception("读取注册表出错!", ex); } finally { if (regKey != null) { regKey.Close(); regKey = null; } if (regSubKey != null) { regSubKey.Close(); regSubKey = null; } } Path = strPathResult; Version = strVersionResult; } http://hi.baidu.com/goga/blog/item/cc8e242d915e423c359bf730.html excelApp = new Excel.Application();excelApp.Version HKEY_LOCAL_MACHINE/Software/Microsoft/Office/11.0/Excel/InstallRoot/ 读注册可能是最直接的方法吧HKEY_LOCAL_MACHINE/Software/Microsoft/Office/11.0/Excel/InstallRoot/ 谁知道C#有什么功能? 关于上传图片创建文件夹的问题,着急,在线等~~~ 关于socket断开后System.IO.IOException异常 在.net2005中c/s程序如何以智能客户端的方式发布 关于struct拷贝的困惑啊,为什么一定要new一步呢? 第二次点按钮没有反映 各位大侠:C#中怎么对密码框进行加密和解密 GridView 添加 button 如何判断一组标签是否闭合 哪里有visual stodio.net下载呀!? .....如何从swf文件里提取音频文件?......... 实例化EXCEL时出错
/// 获取当前某个版本Office的安装路径
/// </summary>
/// <param name="Path">返回当前系统Office安装路径</param>
/// <param name="Version">返回当前系统Office版本信息</param>
public static void GetOfficePath(out string Path,out string Version)
{
string strPathResult = "";
string strVersionResult = "";
string strKeyName = "Path";
object objResult = null;
Microsoft.Win32.RegistryValueKind regValueKind;
Microsoft.Win32.RegistryKey regKey = null;
Microsoft.Win32.RegistryKey regSubKey = null; try
{
regKey = Microsoft.Win32.Registry.LocalMachine; if (regSubKey == null)
{//office97
regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\8.0\Common\InstallRoot", false);
strVersionResult = "office97";
strKeyName = "OfficeBin";
} if (regSubKey == null)
{//Office2000
regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\9.0\Common\InstallRoot", false);
strVersionResult = "office2000";
strKeyName = "Path";
} if (regSubKey == null)
{//officeXp
regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\10.0\Common\InstallRoot", false);
strVersionResult = "officeXP";
strKeyName = "Path";
} if (regSubKey == null)
{//Office2003
regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\11.0\Common\InstallRoot", false);
strVersionResult = "office2003";
strKeyName = "Path";
} if (regSubKey == null)
{//office2007
regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\12.0\Common\InstallRoot", false);
strVersionResult = "office2007";
strKeyName = "Path";
} objResult = regSubKey.GetValue(strKeyName);
regValueKind = regSubKey.GetValueKind(strKeyName);
if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
{
strPathResult = objResult.ToString();
}
}
catch (System.Security.SecurityException ex)
{
throw new System.Security.SecurityException("您没有读取注册表的权限", ex);
}
catch (Exception ex)
{
throw new Exception("读取注册表出错!", ex);
}
finally
{ if (regKey != null)
{
regKey.Close();
regKey = null;
} if (regSubKey != null)
{
regSubKey.Close();
regSubKey = null;
}
} Path = strPathResult;
Version = strVersionResult;
}
excelApp.Version
HKEY_LOCAL_MACHINE/Software/Microsoft/Office/11.0/Excel/InstallRoot/
HKEY_LOCAL_MACHINE/Software/Microsoft/Office/11.0/Excel/InstallRoot/