找不到 Microsoft Visual C++ 2015 Redistributable Programmatically C#
Cannot find Microsoft Visual C++ 2015 Redistributable Programmatically C#
您好,我 运行 在我的电脑上使用了以下代码:
static void Main(string[] args)
{
StringBuilder sbProductCode = new StringBuilder(39);
int iIdx = 0;
while (
0 == MsiEnumProducts(iIdx++, sbProductCode))
{
Int32 productNameLen = 512;
StringBuilder sbProductName = new StringBuilder(productNameLen);
MsiGetProductInfo(sbProductCode.ToString(),
"ProductName", sbProductName, ref productNameLen);
if (sbProductName.ToString().Contains("Microsoft Visual C++ 2015 Redistributable"))
{
Int32 installDirLen = 1024;
StringBuilder sbInstallDir = new StringBuilder(installDirLen);
MsiGetProductInfo(sbProductCode.ToString(),
"InstallLocation", sbInstallDir, ref installDirLen);
Console.WriteLine("ProductName {0}: {1}",
sbProductName, sbInstallDir);
Console.ReadLine();
}
}
}
循环结束,没有找到任何东西。
但是查看控制面板中的程序和功能我可以清楚地看到它已安装,并且名称与字符串中的完全匹配。
那是因为 MSI "products" 不对应 1:1 面向用户的程序和功能列表中显示的条目。对于安装在 Windows 7 上的 VC 2015 x64 运行时,您需要查找两个产品:Microsoft Visual C++ 2015 x64 Minimum Runtime
和 Microsoft Visual C++ 2015 x64 Additional Runtime
.
您好,我 运行 在我的电脑上使用了以下代码:
static void Main(string[] args)
{
StringBuilder sbProductCode = new StringBuilder(39);
int iIdx = 0;
while (
0 == MsiEnumProducts(iIdx++, sbProductCode))
{
Int32 productNameLen = 512;
StringBuilder sbProductName = new StringBuilder(productNameLen);
MsiGetProductInfo(sbProductCode.ToString(),
"ProductName", sbProductName, ref productNameLen);
if (sbProductName.ToString().Contains("Microsoft Visual C++ 2015 Redistributable"))
{
Int32 installDirLen = 1024;
StringBuilder sbInstallDir = new StringBuilder(installDirLen);
MsiGetProductInfo(sbProductCode.ToString(),
"InstallLocation", sbInstallDir, ref installDirLen);
Console.WriteLine("ProductName {0}: {1}",
sbProductName, sbInstallDir);
Console.ReadLine();
}
}
}
循环结束,没有找到任何东西。 但是查看控制面板中的程序和功能我可以清楚地看到它已安装,并且名称与字符串中的完全匹配。
那是因为 MSI "products" 不对应 1:1 面向用户的程序和功能列表中显示的条目。对于安装在 Windows 7 上的 VC 2015 x64 运行时,您需要查找两个产品:Microsoft Visual C++ 2015 x64 Minimum Runtime
和 Microsoft Visual C++ 2015 x64 Additional Runtime
.