检查 电脑上装的access版本

zlb789 2009-05-04 06:14:11

Type type;
object access = null;
object version = null;

type = Type.GetTypeFromProgID("Access.Application");//Access 判断出错 excel可以

if (type == null)
{
MessageBox.Show("没有安装access"); Application.Exit();
}
else
{
access = Activator.CreateInstance(type);
if (access == null)
{
MessageBox.Show("没有安装access");
Application.Exit();
}
else
{
version = type.GetProperty("Version").GetValue(access, null);
PropertyInfo p = type.GetProperty("Visible");
p.SetValue(access, true, null);//设置可见性
MethodInfo[] ms=type.GetMethods();//CloseCurrentDatabase 退出数据库
type.GetMethod("Quit").Invoke(access, null);//type.GetProperty("Visible").ReflectedType
}
}
if (version != null)
{
// MessageBox.Show("Excel版本号是:" + version.ToString());
}


上面如果是判断excel 可以 ,但是如果是access 就出在调用quit 或者CloseCurrentDatabase 方法的时候出错。

怎么解决
...全文
96 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zlb789 2009-05-11
  • 打赏
  • 举报
回复
无满意答案
zlb789 2009-05-09
  • 打赏
  • 举报
回复
没有好答案?
zlb789 2009-05-08
  • 打赏
  • 举报
回复
楼上的 联系发这么多 ?

去掉这个 错是不会错了 但是效果对不 ?
llnet 2009-05-07
  • 打赏
  • 举报
回复
PropertyInfo p = type.GetProperty("Visible");
p.SetValue(access, true, null);//设置可见性
MethodInfo[] ms=type.GetMethods();//CloseCurrentDatabase 退出数据库
type.GetMethod("Quit").Invoke(access, null);//type.GetProperty("Visible").ReflectedType


去掉这几行,可以的
llnet 2009-05-07
  • 打赏
  • 举报
回复
PropertyInfo p = type.GetProperty("Visible");
p.SetValue(access, true, null);//设置可见性
MethodInfo[] ms=type.GetMethods();//CloseCurrentDatabase 退出数据库
type.GetMethod("Quit").Invoke(access, null);//type.GetProperty("Visible").ReflectedType


去掉这几行,可以的
llnet 2009-05-07
  • 打赏
  • 举报
回复
PropertyInfo p = type.GetProperty("Visible");
p.SetValue(access, true, null);//设置可见性
MethodInfo[] ms=type.GetMethods();//CloseCurrentDatabase 退出数据库
type.GetMethod("Quit").Invoke(access, null);//type.GetProperty("Visible").ReflectedType


去掉这几行,可以的
llnet 2009-05-07
  • 打赏
  • 举报
回复
PropertyInfo p = type.GetProperty("Visible");
p.SetValue(access, true, null);//设置可见性
MethodInfo[] ms=type.GetMethods();//CloseCurrentDatabase 退出数据库
type.GetMethod("Quit").Invoke(access, null);//type.GetProperty("Visible").ReflectedType





去掉这几行,可以的
SlaughtChen 2009-05-07
  • 打赏
  • 举报
回复
关注中...
zlb789 2009-05-07
  • 打赏
  • 举报
回复
没人 ?
zlb789 2009-05-06
  • 打赏
  • 举报
回复
自己顶起
zlb789 2009-05-06
  • 打赏
  • 举报
回复
读取 注册表 似乎也可以 我想知道我这里怎么不行
yuanhuiqiao 2009-05-06
  • 打赏
  • 举报
回复
从注册表读取信息
sjf_kk 2009-05-06
  • 打赏
  • 举报
回复
不懂,只能帮顶了。
genius_tong 2009-05-04
  • 打赏
  • 举报
回复
mark~
蓝海D鱼 2009-05-04
  • 打赏
  • 举报
回复
up

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧