home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / NSIS 2.44 / nsis-2.44-setup.exe / Include / WinVer.nsh < prev    next >
Encoding:
Text File  |  2008-12-20  |  13.3 KB  |  473 lines

  1. ; ---------------------
  2. ;      WinVer.nsh
  3. ; ---------------------
  4. ;
  5. ; LogicLib extensions for handling Windows versions and service packs.
  6. ;
  7. ; IsNT checks if the installer is running on Windows NT family (NT4, 2000, XP, etc.)
  8. ;
  9. ;   ${If} ${IsNT}
  10. ;     DetailPrint "Running on NT. Installing Unicode enabled application."
  11. ;   ${Else}
  12. ;     DetailPrint "Not running on NT. Installing ANSI application."
  13. ;   ${EndIf}
  14. ;
  15. ; IsServer checks if the installer is running on a server version of Windows (NT4, 2003, 2008, etc.)
  16. ;
  17. ; AtLeastWin<version> checks if the installer is running on Windows version at least as specified.
  18. ; IsWin<version> checks if the installer is running on Windows version exactly as specified.
  19. ; AtMostWin<version> checks if the installer is running on Windows version at most as specified.
  20. ;
  21. ; <version> can be replaced with the following values:
  22. ;
  23. ;   95
  24. ;   98
  25. ;   ME
  26. ;
  27. ;   NT4
  28. ;   2000
  29. ;   XP
  30. ;   2003
  31. ;   Vista
  32. ;   2008
  33. ;
  34. ; AtLeastServicePack checks if the installer is running on Windows service pack version at least as specified.
  35. ; IsServicePack checks if the installer is running on Windows service pack version exactly as specified.
  36. ; AtMostServicePack checks if the installer is running on Windows service version pack at most as specified.
  37. ;
  38. ; Usage examples:
  39. ;
  40. ;   ${If} ${IsNT}
  41. ;   DetailPrint "Running on NT family."
  42. ;   DetailPrint "Surely not running on 95, 98 or ME."
  43. ;   ${AndIf} ${AtLeastWinNT4}
  44. ;     DetailPrint "Running on NT4 or better. Could even be 2003."
  45. ;   ${EndIf}
  46. ;
  47. ;   ${If} ${AtLeastWinXP}
  48. ;     DetailPrint "Running on XP or better."
  49. ;   ${EndIf}
  50. ;
  51. ;   ${If} ${IsWin2000}
  52. ;     DetailPrint "Running on 2000."
  53. ;   ${EndIf}
  54. ;
  55. ;   ${If} ${IsWin2000}
  56. ;   ${AndIf} ${AtLeastServicePack} 3
  57. ;   ${OrIf} ${AtLeastWinXP}
  58. ;     DetailPrint "Running Win2000 SP3 or above"
  59. ;   ${EndIf}
  60. ;
  61. ;   ${If} ${AtMostWinXP}
  62. ;     DetailPrint "Running on XP or older. Surely not running on Vista. Maybe 98, or even 95."
  63. ;   ${EndIf}
  64. ;
  65. ; Warning:
  66. ;
  67. ;   Windows 95 and NT both use the same version number. To avoid getting NT4 misidentified
  68. ;   as Windows 95 and vice-versa or 98 as a version higher than NT4, always use IsNT to
  69. ;   check if running on the NT family.
  70. ;
  71. ;     ${If} ${AtLeastWin95}
  72. ;     ${And} ${AtMostWinME}
  73. ;       DetailPrint "Running 95, 98 or ME."
  74. ;       DetailPrint "Actually, maybe it's NT4?"
  75. ;       ${If} ${IsNT}
  76. ;         DetailPrint "Yes, it's NT4! oops..."
  77. ;       ${Else}
  78. ;         DetailPrint "Nope, not NT4. phew..."
  79. ;       ${EndIf}
  80. ;     ${EndIf}
  81. ;
  82. ;
  83. ; Other useful extensions are:
  84. ;
  85. ;    * IsWin2003R2
  86. ;    * IsStarterEdition
  87. ;    * OSHasMediaCenter
  88. ;    * OSHasTabletSupport
  89. ;
  90.  
  91. !verbose push
  92. !verbose 3
  93.  
  94. !ifndef ___WINVER__NSH___
  95. !define ___WINVER__NSH___
  96.  
  97. !include LogicLib.nsh
  98. !include Util.nsh
  99.  
  100. # masks for our variables
  101.  
  102. !define _WINVER_VERXBIT  0x00000001
  103. !define _WINVER_MASKVMAJ 0x7F000000
  104. !define _WINVER_MASKVMIN 0x00FF0000
  105.  
  106. !define _WINVER_NTBIT    0x80000000
  107. !define _WINVER_NTMASK   0x7FFFFFFF
  108. !define _WINVER_NTSRVBIT 0x40000000
  109. !define _WINVER_MASKVBLD 0x0000FFFF
  110. !define _WINVER_MASKSP   0x000F0000
  111.  
  112. # possible variable values for different versions
  113.  
  114. !define WINVER_95_NT     0x04000000 ;4.00.0950
  115. !define WINVER_95        0x04000000 ;4.00.0950
  116. !define WINVER_98_NT     0x040a0000 ;4.10.1998
  117. !define WINVER_98        0x040a0000 ;4.10.1998
  118. ;define WINVER_98SE      0x040a0000 ;4.10.2222
  119. !define WINVER_ME_NT     0x045a0000 ;4.90.3000
  120. !define WINVER_ME        0x045a0000 ;4.90.3000
  121. ;define WINVER_NT3d51               ;3.51.1057
  122. !define WINVER_NT4_NT    0x84000000 ;4.00.1381
  123. !define WINVER_NT4       0x04000000 ;4.00.1381
  124. !define WINVER_2000_NT   0x85000000 ;5.00.2195
  125. !define WINVER_2000      0x05000000 ;5.00.2195
  126. !define WINVER_XP_NT     0x85010000 ;5.01.2600
  127. !define WINVER_XP        0x05010000 ;5.01.2600
  128. ;define WINVER_XP64                 ;5.02.3790
  129. !define WINVER_2003_NT   0x85020000 ;5.02.3790
  130. !define WINVER_2003      0x05020000 ;5.02.3790
  131. !define WINVER_VISTA_NT  0x86000000 ;6.00.6000
  132. !define WINVER_VISTA     0x06000000 ;6.00.6000
  133. !define WINVER_2008_NT   0x86000001 ;6.00.6001
  134. !define WINVER_2008      0x06000001 ;6.00.6001
  135.  
  136. # use this to make all nt > 9x
  137.  
  138. !ifdef WINVER_NT4_OVER_W95
  139.   !define __WINVERTMP ${WINVER_NT4}
  140.   !undef WINVER_NT4
  141.   !define /math WINVER_NT4 ${__WINVERTMP} | ${_WINVER_VERXBIT}
  142.   !undef __WINVERTMP
  143. !endif
  144.  
  145. # some definitions from header files
  146.  
  147. !define OSVERSIONINFOA_SIZE   148
  148. !define OSVERSIONINFOEXA_SIZE 156
  149. !define VER_PLATFORM_WIN32_NT 2
  150. !define VER_NT_WORKSTATION    1
  151.  
  152. !define SM_TABLETPC    86
  153. !define SM_MEDIACENTER 87
  154. !define SM_STARTER     88
  155. !define SM_SERVERR2    89
  156.  
  157. # variable declaration
  158.  
  159. !macro __WinVer_DeclareVars
  160.  
  161.   !ifndef __WINVER_VARS_DECLARED
  162.  
  163.     !define __WINVER_VARS_DECLARED
  164.  
  165.     Var /GLOBAL __WINVERV
  166.     Var /GLOBAL __WINVERSP
  167.  
  168.   !endif
  169.  
  170. !macroend
  171.  
  172. # lazy initialization macro
  173.  
  174. !ifmacrondef __WinVer_Call_GetVersionEx
  175.  
  176.   !macro __WinVer_Call_GetVersionEx STRUCT_SIZE
  177.  
  178.     System::Call '*$0(i ${STRUCT_SIZE})'
  179.     System::Call kernel32::GetVersionEx(ir0)i.r3
  180.  
  181.   !macroend
  182.  
  183. !endif
  184.  
  185. !macro __WinVer_InitVars
  186.   # variables
  187.   !insertmacro __WinVer_DeclareVars
  188.  
  189.   # only calculate version once
  190.   StrCmp $__WINVERV "" _winver_noveryet
  191.     Return
  192.   _winver_noveryet:
  193.  
  194.   # push used registers on the stack
  195.   Push $0
  196.   Push $1 ;maj
  197.   Push $2 ;min
  198.   Push $3 ;bld
  199.   Push $R0 ;temp
  200.  
  201.   # allocate memory
  202.   System::Alloc ${OSVERSIONINFOEXA_SIZE}
  203.   Pop $0
  204.  
  205.   # use OSVERSIONINFOEX
  206.   !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOEXA_SIZE}
  207.  
  208.   IntCmp $3 0 "" _winver_ex _winver_ex
  209.     # OSVERSIONINFOEX not allowed (Win9x or NT4 w/SP < 6), use OSVERSIONINFO
  210.     !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOA_SIZE}
  211.   _winver_ex:
  212.  
  213.   # get results from struct
  214.   System::Call '*$0(i.s,i.r1,i.r2,i.r3,i.s,&t128.s,&i2.s,&i2,&i2,&i1.s,&i1)'
  215.  
  216.   # free struct
  217.   System::Free $0
  218.  
  219.   # win9x has major and minor info in high word of dwBuildNumber - remove it
  220.   IntOp $3 $3 & 0xFFFF
  221.  
  222.   # get dwOSVersionInfoSize
  223.   Pop $R0
  224.  
  225.   # get dwPlatformId
  226.   Pop $0
  227.  
  228.   # NT?
  229.   IntCmp $0 ${VER_PLATFORM_WIN32_NT} "" _winver_notnt _winver_notnt
  230.     IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTBIT}
  231.     IntOp $__WINVERV  $__WINVERV  | ${_WINVER_NTBIT}
  232.   _winver_notnt:
  233.  
  234.   # get service pack information
  235.   IntCmp $0 ${VER_PLATFORM_WIN32_NT} _winver_nt "" _winver_nt  # win9x
  236.  
  237.     # get szCSDVersion
  238.     Pop $0
  239.  
  240.     # copy second char
  241.     StrCpy $0 $0 1 1
  242.  
  243.     # discard invalid wServicePackMajor and wProductType
  244.     Pop $R0
  245.     Pop $R0
  246.  
  247.     # switch
  248.     StrCmp $0 'A' "" +3
  249.       StrCpy $0 1
  250.       Goto _winver_sp_done
  251.     StrCmp $0 'B' "" +3
  252.       StrCpy $0 2
  253.       Goto _winver_sp_done
  254.     StrCmp $0 'C' "" +3
  255.       StrCpy $0 3
  256.       Goto _winver_sp_done
  257.     StrCpy $0 0
  258.     Goto _winver_sp_done
  259.  
  260.   _winver_nt: # nt
  261.  
  262.     IntCmp $R0 ${OSVERSIONINFOEXA_SIZE} "" _winver_sp_noex _winver_sp_noex
  263.  
  264.       # discard szCSDVersion
  265.       Pop $0
  266.  
  267.       # get wProductType
  268.       Exch
  269.       Pop $0
  270.  
  271.       # is server?
  272.       IntCmp $0 ${VER_NT_WORKSTATION} _winver_noserver _winver_noserver ""
  273.         IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTSRVBIT}
  274.       _winver_noserver:
  275.  
  276.       # get wServicePackMajor
  277.       Pop $0
  278.  
  279.       # done with sp
  280.       Goto _winver_sp_done
  281.  
  282.     _winver_sp_noex: # OSVERSIONINFO, not OSVERSIONINFOEX
  283.  
  284.       ####  TODO
  285.       ## For IsServer to support < NT4SP6, we need to check the registry
  286.       ## here to see if we are a server and/or DC
  287.  
  288.       # get szCSDVersion
  289.       Pop $0
  290.  
  291.       # discard invalid wServicePackMajor and wProductType
  292.       Pop $R0
  293.       Pop $R0
  294.  
  295.       # get service pack number from text
  296.       StrCpy $R0 $0 13
  297.       StrCmp $R0 "Service Pack " "" +3
  298.         StrCpy $0 $0 "" 13 # cut "Service Pack "
  299.         Goto +2
  300.         StrCpy $0 0 # no service pack
  301.  
  302. !ifdef WINVER_NT4_OVER_W95
  303.       IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
  304. !endif
  305.  
  306.   _winver_sp_done:
  307.  
  308.   # store service pack
  309.   IntOp $0 $0 << 16
  310.   IntOp $__WINVERSP $__WINVERSP | $0
  311.  
  312.   ### now for the version
  313.  
  314.   # is server?
  315.   IntOp $0 $__WINVERSP & ${_WINVER_NTSRVBIT}
  316.  
  317.   # windows xp x64?
  318.   IntCmp $0 0 "" _winver_not_xp_x64 _winver_not_xp_x64 # not server
  319.   IntCmp $1 5 "" _winver_not_xp_x64 _winver_not_xp_x64 # maj 5
  320.   IntCmp $2 2 "" _winver_not_xp_x64 _winver_not_xp_x64 # min 2
  321.     # change XP x64 from 5.2 to 5.1 so it's still XP
  322.     StrCpy $2 1
  323.   _winver_not_xp_x64:
  324.  
  325.   # server 2008?
  326.   IntCmp $0 0 _winver_not_2008 # server
  327.   IntCmp $1 6 "" _winver_not_2008 _winver_not_2008 # maj 6
  328.   IntCmp $2 0 "" _winver_not_2008 _winver_not_2008 # min 0
  329.     # extra bit so Server 2008 comes after Vista SP1 that has the same minor version
  330.     IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
  331.   _winver_not_2008:
  332.  
  333.   # pack version
  334.   IntOp $1 $1 << 24 # VerMajor
  335.   IntOp $__WINVERV $__WINVERV | $1
  336.   IntOp $0 $2 << 16
  337.   IntOp $__WINVERV $__WINVERV | $0 # VerMinor
  338.   IntOp $__WINVERSP $__WINVERSP | $3 # VerBuild
  339.  
  340.   # restore registers
  341.   Pop $R0
  342.   Pop $3
  343.   Pop $2
  344.   Pop $1
  345.   Pop $0
  346.  
  347. !macroend
  348.  
  349. # version comparison LogicLib macros
  350.  
  351. !macro _WinVerAtLeast _a _b _t _f
  352.   !insertmacro _LOGICLIB_TEMP
  353.   ${CallArtificialFunction} __WinVer_InitVars
  354.   IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
  355.   !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  356. !macroend
  357. !macro _WinVerIs _a _b _t _f
  358.   ${CallArtificialFunction} __WinVer_InitVars
  359.   !insertmacro _= $__WINVERV `${_b}` `${_t}` `${_f}`
  360. !macroend
  361. !macro _WinVerAtMost _a _b _t _f
  362.   !insertmacro _LOGICLIB_TEMP
  363.   ${CallArtificialFunction} __WinVer_InitVars
  364.   IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
  365.   !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  366. !macroend
  367.  
  368. !macro __WinVer_DefineOSTest Test OS Suffix
  369.   !define ${Test}Win${OS} `"" WinVer${Test} ${WINVER_${OS}${Suffix}}`
  370. !macroend
  371.  
  372. !macro __WinVer_DefineOSTests Test Suffix
  373.   !insertmacro __WinVer_DefineOSTest ${Test} 95    '${Suffix}'
  374.   !insertmacro __WinVer_DefineOSTest ${Test} 98    '${Suffix}'
  375.   !insertmacro __WinVer_DefineOSTest ${Test} ME    '${Suffix}'
  376.   !insertmacro __WinVer_DefineOSTest ${Test} NT4   '${Suffix}'
  377.   !insertmacro __WinVer_DefineOSTest ${Test} 2000  '${Suffix}'
  378.   !insertmacro __WinVer_DefineOSTest ${Test} XP    '${Suffix}'
  379.   !insertmacro __WinVer_DefineOSTest ${Test} 2003  '${Suffix}'
  380.   !insertmacro __WinVer_DefineOSTest ${Test} VISTA '${Suffix}'
  381.   !insertmacro __WinVer_DefineOSTest ${Test} 2008  '${Suffix}'
  382. !macroend
  383.  
  384. !insertmacro __WinVer_DefineOSTests AtLeast ""
  385. !insertmacro __WinVer_DefineOSTests Is _NT
  386. !insertmacro __WinVer_DefineOSTests AtMost ""
  387.  
  388. # version feature LogicLib macros
  389.  
  390. !macro _IsNT _a _b _t _f
  391.   !insertmacro _LOGICLIB_TEMP
  392.   ${CallArtificialFunction} __WinVer_InitVars
  393.   IntOp $_LOGICLIB_TEMP $__WINVERSP & ${_WINVER_NTBIT}
  394.   !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  395. !macroend
  396. !define IsNT `"" IsNT ""`
  397.  
  398. !macro _IsServerOS _a _b _t _f
  399.   !insertmacro _LOGICLIB_TEMP
  400.   ${CallArtificialFunction} __WinVer_InitVars
  401.   IntOp $_LOGICLIB_TEMP $__WINVERSP & ${_WINVER_NTSRVBIT}
  402.   !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  403. !macroend
  404. !define IsServerOS `"" IsServerOS ""`
  405.  
  406. # service pack macros
  407.  
  408. !macro _WinVer_GetServicePackLevel OUTVAR
  409.   ${CallArtificialFunction} __WinVer_InitVars
  410.   IntOp ${OUTVAR} $__WINVERSP & ${_WINVER_MASKSP}
  411.   IntOp ${OUTVAR} ${OUTVAR} >> 16
  412. !macroend
  413. !define WinVerGetServicePackLevel '!insertmacro _WinVer_GetServicePackLevel '
  414.  
  415. !macro _AtLeastServicePack _a _b _t _f
  416.   !insertmacro _LOGICLIB_TEMP
  417.   ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  418.   !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  419. !macroend
  420. !define AtLeastServicePack `"" AtLeastServicePack`
  421.  
  422. !macro _AtMostServicePack _a _b _t _f
  423.   !insertmacro _LOGICLIB_TEMP
  424.   ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  425.   !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  426. !macroend
  427. !define AtMostServicePack `"" AtMostServicePack`
  428.  
  429. !macro _IsServicePack _a _b _t _f
  430.   !insertmacro _LOGICLIB_TEMP
  431.   ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  432.   !insertmacro _= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  433. !macroend
  434. !define IsServicePack `"" IsServicePack`
  435.  
  436. # special feature LogicLib macros
  437.  
  438. !macro _WinVer_SysMetricCheck m _b _t _f
  439.   !insertmacro _LOGICLIB_TEMP
  440.   System::Call user32::GetSystemMetrics(i${m})i.s
  441.   pop $_LOGICLIB_TEMP
  442.   !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  443. !macroend
  444.  
  445. !define IsWin2003R2        `${SM_SERVERR2}    WinVer_SysMetricCheck ""`
  446. !define IsStarterEdition   `${SM_STARTER}     WinVer_SysMetricCheck ""`
  447. !define OSHasMediaCenter   `${SM_MEDIACENTER} WinVer_SysMetricCheck ""`
  448. !define OSHasTabletSupport `${SM_TABLETPC}    WinVer_SysMetricCheck ""`
  449.  
  450. # version retrieval macros
  451.  
  452. !macro __WinVer_GetVer var rshift mask outvar
  453.   ${CallArtificialFunction} __WinVer_InitVars
  454.   !if "${mask}" != ""
  455.     IntOp ${outvar} ${var} & ${mask}
  456.     !if "${rshift}" != ""
  457.       IntOp ${outvar} ${outvar} >> ${rshift}
  458.     !endif
  459.   !else
  460.     IntOp ${outvar} ${var} >> ${rshift}
  461.   !endif
  462. !macroend
  463.  
  464. !define WinVerGetMajor '!insertmacro __WinVer_GetVer $__WINVERV  24 ${_WINVER_MASKVMAJ}'
  465. !define WinVerGetMinor '!insertmacro __WinVer_GetVer $__WINVERV  16 ${_WINVER_MASKVMIN}'
  466. !define WinVerGetBuild '!insertmacro __WinVer_GetVer $__WINVERSP "" ${_WINVER_MASKVBLD}'
  467.  
  468. # done
  469.  
  470. !endif # !___WINVER__NSH___
  471.  
  472. !verbose pop
  473.