[代码]获取系统安装的MS Offfice信息(是否安装、版本、安装路径)

龙宜坡 龙宜坡 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
N久么发过贴,冒个泡,发个代码,不妥之处请指正!
参考了高手用VB6.0写的

using System;
using System.Collections.Generic;
using System.Text;

namespace WpsTest
{
public class OfficeOperator
{
#region 方法

#region public static
/// <summary>
/// 检测MS-Office是否正确安装
/// 通过注册表检测
/// </summary>
/// <param name="version">获得安装的版本号,如office2000,office2003,office2007</param>
/// <returns></returns>
public static bool IsInstall(out string Version)
{
bool result = false;
string officePath = "";
string officeVersion = "";

Version = "";
GetOfficePath(out officePath, out officeVersion);

if (!string.IsNullOrEmpty(officeVersion) && !string.IsNullOrEmpty(officePath))
{
result = true;
Version = officeVersion;
}

return result;
}

/// <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;
}
#endregion public static

#endregion 方法
}
}


以下是使用

        private void btnGetOfficePath_Click(object sender, EventArgs e)
{
string officePath = "";
string officeVersion = "";
try
{
OfficeOperator.GetOfficePath(out officePath,out officeVersion);
}
catch (Exception ex)
{
MessageBox.Show("无法获取系统Office信息");
}
if (!string.IsNullOrEmpty(officePath) && !string.IsNullOrEmpty(officeVersion))
{
MessageBox.Show(string.Format("版本:{0}\r\n安装路径:{1}",officeVersion,officePath));
}
}

//是否安装及版本
private void btnIsInstall_Click(object sender, EventArgs e)
{
try
{
string version = "";
if (OfficeOperator.IsInstall(out version))
{
MessageBox.Show(string.Format("当前安装了{0}", version));
}
else
{
MessageBox.Show("您当前还没有安装微软Office系列软件");
}
}
catch(Exception ex)
{
MessageBox.Show("无法获取系统Office信息");
}
}

N久么发过贴,冒个泡,发个代码,不妥之处请指正!
...全文

相关推荐

fengmian123

fengmian123

CiYuanShuos

QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx

QYR-18900-2026-2032全球与中国智能旋转导向钻井系统市场现状及未来发展趋势 Sample-shijunzhong.docx

qyresearch报告

XERJ 是一款受到社区信赖的本地 AI 搜索引擎

XERJ 是一款受到社区信赖的本地 AI 搜索引擎,能自动为任意文件夹建立索引,让编程智能体直接检索所需代码,省去逐个读取文件消耗的 token。它的主要用途是参考现有实现来写代码(reference coding):接到任务后,智能体下载与任务相关的开源仓库,建立索引,再查阅这些项目的解决方法。 在一项对照研究中,这种做法让智能体的输出 token 用量降至原来的约 1/2.7,同时保持 16/16 的任务完成率(案例研究)。用户在日常开发中报告的用量约为原来的 1/5(使用反馈)。有了可检索的参考实现,较小、较便宜的模型也可能胜过只凭记忆工作的昂贵模型,减少反复修改的次数。把下面这段提示词交给智能体即可开始

yiersansiwu123d

DocRes.Vulkan.WinForms.VS2022-Source-r1.1-20261016-102846-206.zip

DocRes.Vulkan.WinForms.VS2022-Source-r1.1-20261016-102846-206.zip 博客地址:https://blog.csdn.net/lw112190/article/details/168119884

天天代码码天天

电力系统连锁故障一种用于识别引发连锁故障的多重故障集合的“随机化学”算法研究(Matlab代码实现)

内容概要:本文研究了一种基于“随机化学”算法的多重故障集合识别方法,旨在准确识别电力系统中可能引发连锁故障的关键故障组合。该方法结合ADMM(交替方向乘子法)优化框架,建立了考虑连锁故障传播路径的N-k多阶段双层优化模型,并设计了高效的故障场景筛选机制,以应对大规模电网中连锁故障风险分析的高复杂性挑战。通过Matlab代码实现了算法的全流程仿真验证,结果表明该方法在识别高风险故障集方面具有较高的有效性与计算效率,为电力系统的安全评估、脆弱性分析及预防控制策略制定提供了先进的技术支撑。; 适合人群:具备电力系统分析、优化理论基础及Matlab编程能力,从事电力系统安全稳定、连锁故障防御、风险评估等相关研究的科研人员与工程技术人员。; 使用场景及目标:①应用于大规模电力系统中高风险N-k故障场景的快速识别与排序;②支撑基于N-k安全准则的电网脆弱环节分析与主动防御策略设计;③为运行调度、规划检修及应急管理提供科学的故障预案筛选工具。; 阅读建议:建议读者结合Matlab代码与论文中的模型推导,深入理解随机化学算法在双层优化框架中的实现逻辑,重点关注ADMM的分解协调机制与故障传播路径的建模方法,并通过复现仿真案例掌握其在实际电网中的应用流程与参数设置技巧。

荧光Matlab
评论 15
收藏 已收藏
分享
返回顶部
龙宜坡
C# 111,128 成员 642,536 内容