如何使用InstallShield升级代码GUID在Inno Setup中卸载相关产品 [英] How do I uninstall related products in Inno Setup using an InstallShield Upgrade Code GUID

查看:113
本文介绍了如何使用InstallShield升级代码GUID在Inno Setup中卸载相关产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们公司已从使用InstallShield Express切换为使用Inno Setup(5.5.2版).我们已经有多年使用InstallShield进行旧安装的情况,但是始终依靠InstallShield的升级代码GUID来处理以前版本的卸载.

Our company has switched from using InstallShield Express to using Inno Setup (5.5.2 version). We've got years of old installs utilizing InstallShield, but have always relied on InstallShield's Upgrade Code GUID to handle the uninstall of the previous version.

我需要能够从新的Inno Setup安装程序中卸载任何以前的InstallShield安装版本.

I need to be able to uninstall any previous InstallShield installed version from our new Inno Setup installer.

经过一番研究,看来我需要调用MsiEnumRelatedProducts(),然后卸载找到的所有产品.

After some research it looks like I need to call MsiEnumRelatedProducts() and then uninstall any found products.

我找到了此链接 http://www.inno-setup.de/showthread.php?s=415e3895fda3e26e42739b004c0f51fb&t=2857 ).看起来他已经很接近了,但是他从未发布最终解决方案.

I found this link http://www.microsofttranslator.com/bv.aspx?from=de&to=en&a=http%3A%2F%2Fwww.inno-setup.de%2Fshowthread.php%3Fs%3D415e3895fda3e26e42739b004c0f51fb%26t%3D2857 (original in German http://www.inno-setup.de/showthread.php?s=415e3895fda3e26e42739b004c0f51fb&t=2857). It looks like he got pretty close, but he never posts his final solution.

他说的代码有效(但对我来说崩溃了):

Code he says works (but crashes for me):

type
  TProductBuf = array[0..39] of char;

function MsiEnumRelatedProducts(lpUpgradeCode:string;
  dwReserved, iProductIndex:cardinal; 
  var lpProductBuf:TProductBuf) : cardinal;
external 'MsiEnumRelatedProductsW@msi.dll setuponly stdcall';

function InitializeSetup : boolean;
var
  ret, i, j : cardinal;
  ProductBuf : TProductBuf;
  ProductCode : string;

begin
  Result := true;
  i := 0;
  repeat
  ret := MsiEnumRelatedProducts('{#UPGRADE_CODE}', 0, i, ProductBuf);
    if ret=0 then
    begin
      ProductCode := '';
      for j := 0 to 39 do
      begin
        if ProductBuf[j] = #0 then
          break;
        ProductCode := ProductCode + ProductBuf[j];
      end;
      Result := uninstallOther(ProductCode);
    end;
    i := i+1;
  until ret <> 0;
end;

他说这样会更容易吗?

SetLength(ProductCode, Pos(#0, ProductCode) - 1);

我是Pascal脚本的新手,我陷入了整个SetLength()部分.在他说的功能中会替换掉什么,但是会崩溃?

I'm new to Pascal scripting and I'm getting stuck on the whole SetLength() part. What does it replace in the function he says works, but crashes?

由于其他人说要切换到字符串,因此我应该摆脱这一点:

Since the other persons says to switch to string, should I get rid of this:

type
  TProductBuf = array[0..39] of char;

如果有人可以用英语给我看最后的工作功能,那就太好了!

If anyone could show me a final working function in English, it would be awesome!!!

提前谢谢!

我使用的是Inno Setup Compiler的ANSI版本.

I am using the ANSI version of the Inno Setup Compiler.

推荐答案

这是未经测试的翻译,应仅在消息框中打印出相关产品的GUID.该代码应与ANSI以及Unicode版本的InnoSetup一起使用:

Here's an untested translation, which should just print out the related product GUIDs in message boxes. The code should work with ANSI as well as with Unicode versions of InnoSetup:

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif

#define UPGRADE_CODE "<your upgrade here>"

const
  ERROR_SUCCESS = $00000000;
  ERROR_NOT_ENOUGH_MEMORY = $00000008;
  ERROR_INVALID_PARAMETER = $00000057;
  ERROR_NO_MORE_ITEMS = $00000103;
  ERROR_BAD_CONFIGURATION = $0000064A;

function MsiEnumRelatedProducts(lpUpgradeCode: string; dwReserved: DWORD;
  iProductIndex: DWORD; lpProductBuf: string): UINT;
  external 'MsiEnumRelatedProducts{#AW}@msi.dll stdcall';

function InitializeSetup: Boolean;
var
  I: Integer;
  ProductBuf: string;
begin
  Result := True;

  I := 0;
  SetLength(ProductBuf, 39);

  while MsiEnumRelatedProducts('{#UPGRADE_CODE}', 0, I, ProductBuf) = ERROR_SUCCESS do
  begin
    MsgBox(ProductBuf, mbInformation, MB_OK);
    I := I + 1;
    SetLength(ProductBuf, 39);
  end;
end;

这篇关于如何使用InstallShield升级代码GUID在Inno Setup中卸载相关产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆