Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在MSVS的.msi项目中查找第三方应用程序的安装位置_Windows_Dll_Installation_Visual C++ - Fatal编程技术网

Windows 在MSVS的.msi项目中查找第三方应用程序的安装位置

Windows 在MSVS的.msi项目中查找第三方应用程序的安装位置,windows,dll,installation,visual-c++,Windows,Dll,Installation,Visual C++,上下文:我有一些插件(实际上只是具有不同扩展名的DLL)需要安装在第三方应用程序的子文件夹中。通常只需将它们复制到上述文件夹就足够了,但偶尔也需要安装其他库。我想让这个过程对于用户来说不那么容易出错,所以我考虑过在VisualStudio中使用安装程序项目来创建.msi,但是我在正确配置安装位置时遇到了问题 它似乎假定安装程序是为一个完整的应用程序设计的,并且默认为一个位置,例如C:\Program Files\MyApp\,但我真正需要的是C:\Program Files\\Plugins。我

上下文:我有一些插件(实际上只是具有不同扩展名的DLL)需要安装在第三方应用程序的子文件夹中。通常只需将它们复制到上述文件夹就足够了,但偶尔也需要安装其他库。我想让这个过程对于用户来说不那么容易出错,所以我考虑过在VisualStudio中使用安装程序项目来创建.msi,但是我在正确配置安装位置时遇到了问题

它似乎假定安装程序是为一个完整的应用程序设计的,并且默认为一个位置,例如C:\Program Files\MyApp\,但我真正需要的是C:\Program Files\\Plugins。我不想假设用户在任何特定的位置安装了第三方应用程序,所以我想要的是找到其他应用程序安装位置的方法。我搜索了微软的文档,自己做了一些实验,但没有成功


假设这是可能的,有人知道如何实现我想要的吗?

大多数应用程序都会将其安装位置写入注册表中的某个位置。我们读取以下注册表项下的值以查找Microsoft Word安装位置

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe]

不幸的是,没有标准的方法来检索特定应用程序的安装位置。您必须搜索注册表才能找到所需内容。

如果您的应用程序使用Windows installer,您可以尝试以下方法(C#):

Type Type=Type.GetTypeFromProgID(“WindowsInstaller.Installer”);
安装程序msi=(安装程序)Activator.CreateInstance(类型);
foreach(msi.Products中的字符串productcode)
{
字符串productname=msi.get_ProductInfo(产品代码,“InstalledProductName”);
如果(productname.Contains(“”)
{
字符串installdir=msi.get_ProductInfo(productcode,“InstallLocation”);
WriteLine(“{0}:{1}@({2})”,productcode,productname,installdir);
}
}
    Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");
    Installer msi = (Installer)Activator.CreateInstance(type);
    foreach (string productcode in msi.Products)
    {
        string productname = msi.get_ProductInfo(productcode, "InstalledProductName");
        if (productname.Contains("<YOUR PRODUCT NAME HERE>"))
        {
            string installdir = msi.get_ProductInfo(productcode, "InstallLocation");
            Console.WriteLine("{0}: {1} @({2})", productcode, productname, installdir);
        }
    }