C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件
2012-02-17 15:16
866 查看
http://hi.baidu.com/yebihaigsino/blog/item/36e4ea6f864743d281cb4ad9.html
http://hi.baidu.com/devzhao/blog/item/3f527e435e91de149313c6b7.html
方法一:
异常判断法(根据返回结果形式)
// 使用地方
private void buttonOk_Click(object sender, EventArgs e)
{
if (codeboolisExcelInstalled())
{
MessageBox.Show("本机已安装Excel文件");
}
else
{
MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office 2003", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
//判断本机是否安装Excel文件方法
private bool codeboolisExcelInstalled()
{
Type type = Type.GetTypeFromProgID("Excel.Application");
return type != null;
}
====================================================================
方法二:
注册表检查发
判断注册表里有没有SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\Excel.exe 其中12.0 11.0需要同时判断,因为11.0是office 2003 12.0是office 2007
// 使用地方
private void buttonOk_Click(object sender, EventArgs e)
{
if (ExistsRegedit())
{
MessageBox.Show("本机已安装Excel文件");
}
else
{
MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office 2003", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
/// <summary>
/// Self_Variable:查询注册表某个键值是否存在
/// </summary>
/// <returns></returns>
public bool ExistsRegedit()
{
bool ifused = false;
RegistryKey rk = Registry.LocalMachine;
RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");
RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");
//检查本机是否安装Office2003
if (akey != null)
{
string file03 = akey.GetValue("Path").ToString();
if (File.Exists(file03 + "Excel.exe"))
{
ifused = true;
}
}
//检查本机是否安装Office2007
if (akeytwo != null)
{
string file07 = akeytwo.GetValue("Path").ToString();
if (File.Exists(file07 + "Excel.exe"))
{
ifused = true;
}
}
return ifused;
}
=======================================
string strInstallPath = file03 /file07 + "Excel.exe";
//获取Excel进程信息
System.Diagnostics.ProcessStartInfo psInfo = new System.Diagnostics.ProcessStartInfo(strInstallPath);
//运行Excel
System.Diagnostics.Process.Start(strInstallPath);
http://hi.baidu.com/devzhao/blog/item/3f527e435e91de149313c6b7.html
方法一:
异常判断法(根据返回结果形式)
// 使用地方
private void buttonOk_Click(object sender, EventArgs e)
{
if (codeboolisExcelInstalled())
{
MessageBox.Show("本机已安装Excel文件");
}
else
{
MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office 2003", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
//判断本机是否安装Excel文件方法
private bool codeboolisExcelInstalled()
{
Type type = Type.GetTypeFromProgID("Excel.Application");
return type != null;
}
====================================================================
方法二:
注册表检查发
判断注册表里有没有SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\Excel.exe 其中12.0 11.0需要同时判断,因为11.0是office 2003 12.0是office 2007
// 使用地方
private void buttonOk_Click(object sender, EventArgs e)
{
if (ExistsRegedit())
{
MessageBox.Show("本机已安装Excel文件");
}
else
{
MessageBox.Show("当前系统没有发现可执行的Excel文件, 如需使用Excel功能请先安装office 2003", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
/// <summary>
/// Self_Variable:查询注册表某个键值是否存在
/// </summary>
/// <returns></returns>
public bool ExistsRegedit()
{
bool ifused = false;
RegistryKey rk = Registry.LocalMachine;
RegistryKey akey = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\11.0\\Word\\InstallRoot\\");
RegistryKey akeytwo = rk.OpenSubKey(@"SOFTWARE\\Microsoft\\Office\\12.0\\Word\\InstallRoot\\");
//检查本机是否安装Office2003
if (akey != null)
{
string file03 = akey.GetValue("Path").ToString();
if (File.Exists(file03 + "Excel.exe"))
{
ifused = true;
}
}
//检查本机是否安装Office2007
if (akeytwo != null)
{
string file07 = akeytwo.GetValue("Path").ToString();
if (File.Exists(file07 + "Excel.exe"))
{
ifused = true;
}
}
return ifused;
}
=======================================
string strInstallPath = file03 /file07 + "Excel.exe";
//获取Excel进程信息
System.Diagnostics.ProcessStartInfo psInfo = new System.Diagnostics.ProcessStartInfo(strInstallPath);
//运行Excel
System.Diagnostics.Process.Start(strInstallPath);
相关文章推荐
- C# 判断本机是否安装Excel及多版本安装?获取Excel进程信息和打开Excel应用软件
- 获取手机上apk文件信息类,主要是判断是否安装再手机上了,安装的版本比较现有apk版本信息
- 在C#中如何获取系统中所安装的所有软件信息,还有如何打开系统中某个程序
- 获取已安装应用信息,判断是否为系统应用
- 获取软件所有快捷方式名称,判断本地是否安装,并打开
- Android菜鸟笔记- 获取未安装的APK图标、版本、包名、名称、是否安装、安装、打开
- C#判断某软件是否安装
- C#获取32位或者64位系统安装软件信息
- Android - 安装及卸载应用,启动应用程序,分享,详细信息,设备进程信息获取,获取进程占用RAM,清理进程
- 获取未安装的APK图标、版本、包名、名称、是否安装、安装、打开
- android获取所有应用信息,判断系统应用或第三方应用,监听应用安装和卸载
- 获取所有安装在手机上的应用软件的信息
- C#中判断某软件是否已安装
- 获取手机中所有已安装的应用,并判断是否系统应用
- C#判断某软件是否安装
- 获取所有应用信息,判断系统应用或第三方应用,监听应用安装和卸载
- 获取未安装的APK图标、版本、包名、名称、是否安装、安装、打开
- 手机浏览器下判断是否安装某app,并判断是否打开该应用
- android获取应用信息,判断应用来源,监听应用的安装和卸载
- QT cmd判断进程是否存在 获取进程信息 关闭进程