gpt4 book ai didi

c# - 检查微软组件是否存在

转载 作者:行者123 更新时间:2023-11-30 12:19:05 24 4
gpt4 key购买 nike

我想检查某些 Microsoft 组件是否像 wmencoder、directx 或 wmplayer是否安装。如果安装了,我也可以得到它的版本号吗?

我该怎么做?

提前致谢。

最佳答案

我使用下面的代码来确定是否安装了其他应用程序,但是您需要知道在注册表中安装该应用程序的“唯一”产品代码(来自 Visual Studio 中的安装项目)。

包含

using System.Diagnostics;
using Microsoft.Win32;

用法:

// HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{0006F03A-0000-0000-C000-000000000046} << This is outlook 2003
String retval = "";

// Look to see if Outlook 2003 is installed and if it is...
if ((checkComServerExists("{0006F03A-0000-0000-C000-000000000046}", out retval)))
{
// Update boolean flag if we get this far so we don't have to check again
Console.WriteLine("Office CSLID exists - Version: " + retval);
}

功能:

// Checks to see if the given CLSID is registerd and exists on the system
private static Boolean checkComServerExists(String CLSID, out String retval)
{
RegistryKey myRegKey = Registry.LocalMachine;
Object val;

try
{
// get the pathname to the COM server DLL/EXE if the key exists
myRegKey = myRegKey.OpenSubKey("SOFTWARE\\Classes\\CLSID\\" + CLSID + "\\LocalServer32");
val = myRegKey.GetValue(null); // the null gets default
}
catch
{
retval = "CLSID not registered";
return false;
}

FileVersionInfo myFileVersionInfo = null;
try
{
// parse out the version number embedded in the resource
// in the DLL
myFileVersionInfo = FileVersionInfo.GetVersionInfo(val.ToString());
}
catch
{
retval = String.Format("DLL {0} not found", val.ToString());
return false;
}

retval = myFileVersionInfo.FileVersion;
return true;
}

关于c# - 检查微软组件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/572581/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com