2014年5月15日木曜日

nsisでMsiQueryProductState

Access Runtime 2010が入っていなければ、チェックを入れる。
Microsoft SQL Server 2008 Native Client x86/x64が入っていなければ、チェックを入れる。
例:
!include "LogicLib.nsh"

  !macro _IsProductInstalled _a _b _t _f
    Push $0
    !insertmacro _LOGICLIB_TEMP
    StrCpy $0 `${_b}`
    System::Call 'msi.dll::MsiQueryProductStateA(t) i(r0) .r0'
    StrCpy $_LOGICLIB_TEMP $0
    Pop $0
    !insertmacro _= $_LOGICLIB_TEMP 5 `${_t}` `${_f}`
  !macroend
  !define IsProductInstalled `"" IsProductInstalled`

Function .onInit
  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{90140000-001C-0000-0000-0000000FF1CE}" "InstallLocation"
  ${If} $0 == ""
    SectionSetFlags ${AccessDatabaseEngine} 1
  ${EndIf}

  ${If} "$PROGRAMFILES32" == "$PROGRAMFILES64"
    ${IfNot} ${IsProductInstalled} "{A51AFEE1-ED96-45F1-85E4-6A41BC4461C3}" ;x86
      SectionSetFlags ${x86} 1
    ${EndIf}
  ${Else}
    ${IfNot} ${IsProductInstalled} "{5F3BA538-ADB6-48C4-90B1-179C0358C53E}" ;x64
      SectionSetFlags ${x64} 1
    ${EndIf}
  ${EndIf}

FunctionEnd
若干、修正しました。5/15 11:43, 11:52

INSTALLSTATEの定義は次の通り:
typedef enum tagINSTALLSTATE
{
 INSTALLSTATE_NOTUSED      = -7,  // component disabled
 INSTALLSTATE_BADCONFIG    = -6,  // configuration data corrupt
 INSTALLSTATE_INCOMPLETE   = -5,  // installation suspended or in progress
 INSTALLSTATE_SOURCEABSENT = -4,  // run from source, source is unavailable
 INSTALLSTATE_MOREDATA     = -3,  // return buffer overflow
 INSTALLSTATE_INVALIDARG   = -2,  // invalid function argument
 INSTALLSTATE_UNKNOWN      = -1,  // unrecognized product or feature
 INSTALLSTATE_BROKEN       =  0,  // broken
 INSTALLSTATE_ADVERTISED   =  1,  // advertised feature
 INSTALLSTATE_REMOVED      =  1,  // component being removed (action state, not settable)
 INSTALLSTATE_ABSENT       =  2,  // uninstalled (or action state absent but clients remain)
 INSTALLSTATE_LOCAL        =  3,  // installed on local drive
 INSTALLSTATE_SOURCE       =  4,  // run from source, CD or net
 INSTALLSTATE_DEFAULT      =  5,  // use default, local or source
} INSTALLSTATE;

Windows Installerの細かい所は存じませんが、5が帰ってきたらセットアップ済みのようです。

MsiQueryProductState function
http://msdn.microsoft.com/en-us/library/aa370363(v=vs.85).aspx

INSTALLSTATE_UNKNOWN (-1)
The product is neither advertised or installed.

INSTALLSTATE_ADVERTISED (1)
The product is advertised but not installed.

INSTALLSTATE_ABSENT (2)
The product is installed for a different user.

INSTALLSTATE_DEFAULT (5)
The product is installed for the current user.

0 件のコメント:

コメントを投稿