【问题标题】:Getting Error result in System::call for MsiEnumProducts and GetLastError in NSIS script在 NSIS 脚本中获取 System::call for MsiEnumProducts 和 GetLastError 的错误结果
【发布时间】:2012-03-12 01:23:19
【问题描述】:

我编写了以下脚本来从 MSI 枚举已安装的产品。

!include LogicLib.nsh

!define MsiGetProductCodeFromName "!insertmacro MsiGetProductCodeFromName"

!macro MsiGetProductCodeFromName MSINSISPRODUCTNAME
        Push ${MSINSISPRODUCTNAME}
        Call MsiGetProductCodeFromName
!macroend

Function MsiGetProductCodeFromName
    ;================
    ; Stack : <ProductName>, ...
    ;================

    Exch $0         ; ProductName
    Push $1         ; For internal use as buffer for ProductCode
    Push $2         ; For internal use as counter to MsiEnumProducts
    Push $3         ; For internal use as result of MsiEnumProducts

    ; loop through all productcodes
    Strcpy $2 0

    System::Call "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
    DetailPrint "User name - $0"
    DetailPrint "String length - $1"
    DetailPrint "Return value - $2"

    loop:
    DetailPrint "Calling MsiEnumProducts ( $2, $1 )"
    System::call "msi::MsiEnumProducts (i r2, t .r1) i.r3"
    DetailPrint "Result = $3"
    System::call "kernel32::GetLastError () i.r3"
    DetailPrint "LastError = $3"
    ${If} $R1 == 0
            DetailPrint $1
            Intop $R0 $R0 + 1
            goto loop
    ${Endif}

    end:

    Pop $3
    Pop $2
    Exch
    Pop $0

    ;=========================
    ; Stack : <ProductCode>, ...
    ; ========================
FunctionEnd

当我以下列方式使用上述脚本时:

${MsiGetProductCodeFromName} ${PRODUCT_NAME}

我得到以下输出:

Calling MsiEnumProducts(0, )
Result = error
LastError = error
Completed

请注意,这不包括系统调用 GetUserName 的输出,它工作正常。

任何帮助将不胜感激。

【问题讨论】:

    标签: plugins windows-installer system nsis


    【解决方案1】:

    对 MsiEnumProducts 的第一次调用必须从索引 0 开始,因此在循环标签之前添加 Strcpy $2 0

    我不确定你是否可以在 dll::function 和() 之间留一个空格,当你刚刚从系统插件中得到“错误”时,这通常意味着语法有问题。

    您不能调用 kernel32::GetLastError 并获得有效结果,它必须是原始调用的一部分:System::Call 'dll::function() ?e',然后将错误代码从堆栈中弹出...

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-22
      • 2015-08-24
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多