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