WinVer.nsh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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. !verbose push
  91. !verbose 3
  92. !ifndef ___WINVER__NSH___
  93. !define ___WINVER__NSH___
  94. !include LogicLib.nsh
  95. !include Util.nsh
  96. # masks for our variables
  97. !define _WINVER_VERXBIT 0x00000001
  98. !define _WINVER_MASKVMAJ 0x7F000000
  99. !define _WINVER_MASKVMIN 0x00FF0000
  100. !define _WINVER_NTBIT 0x80000000
  101. !define _WINVER_NTMASK 0x7FFFFFFF
  102. !define _WINVER_NTSRVBIT 0x40000000
  103. !define _WINVER_MASKVBLD 0x0000FFFF
  104. !define _WINVER_MASKSP 0x000F0000
  105. # possible variable values for different versions
  106. !define WINVER_95_NT 0x04000000 ;4.00.0950
  107. !define WINVER_95 0x04000000 ;4.00.0950
  108. !define WINVER_98_NT 0x040a0000 ;4.10.1998
  109. !define WINVER_98 0x040a0000 ;4.10.1998
  110. ;define WINVER_98SE 0x040a0000 ;4.10.2222
  111. !define WINVER_ME_NT 0x045a0000 ;4.90.3000
  112. !define WINVER_ME 0x045a0000 ;4.90.3000
  113. ;define WINVER_NT3d51 ;3.51.1057
  114. !define WINVER_NT4_NT 0x84000000 ;4.00.1381
  115. !define WINVER_NT4 0x04000000 ;4.00.1381
  116. !define WINVER_2000_NT 0x85000000 ;5.00.2195
  117. !define WINVER_2000 0x05000000 ;5.00.2195
  118. !define WINVER_XP_NT 0x85010000 ;5.01.2600
  119. !define WINVER_XP 0x05010000 ;5.01.2600
  120. ;define WINVER_XP64 ;5.02.3790
  121. !define WINVER_2003_NT 0x85020000 ;5.02.3790
  122. !define WINVER_2003 0x05020000 ;5.02.3790
  123. !define WINVER_VISTA_NT 0x86000000 ;6.00.6000
  124. !define WINVER_VISTA 0x06000000 ;6.00.6000
  125. !define WINVER_2008_NT 0x86000001 ;6.00.6001
  126. !define WINVER_2008 0x06000001 ;6.00.6001
  127. # use this to make all nt > 9x
  128. !ifdef WINVER_NT4_OVER_W95
  129. !define __WINVERTMP ${WINVER_NT4}
  130. !undef WINVER_NT4
  131. !define /math WINVER_NT4 ${__WINVERTMP} | ${_WINVER_VERXBIT}
  132. !undef __WINVERTMP
  133. !endif
  134. # some definitions from header files
  135. !define OSVERSIONINFOA_SIZE 148
  136. !define OSVERSIONINFOEXA_SIZE 156
  137. !define VER_PLATFORM_WIN32_NT 2
  138. !define VER_NT_WORKSTATION 1
  139. !define SM_TABLETPC 86
  140. !define SM_MEDIACENTER 87
  141. !define SM_STARTER 88
  142. !define SM_SERVERR2 89
  143. # variable declaration
  144. !macro __WinVer_DeclareVars
  145. !ifndef __WINVER_VARS_DECLARED
  146. !define __WINVER_VARS_DECLARED
  147. Var /GLOBAL __WINVERV
  148. Var /GLOBAL __WINVERSP
  149. !endif
  150. !macroend
  151. # lazy initialization macro
  152. !ifmacrondef __WinVer_Call_GetVersionEx
  153. !macro __WinVer_Call_GetVersionEx STRUCT_SIZE
  154. System::Call '*$0(i ${STRUCT_SIZE})'
  155. System::Call kernel32::GetVersionEx(ir0)i.r3
  156. !macroend
  157. !endif
  158. !macro __WinVer_InitVars
  159. # variables
  160. !insertmacro __WinVer_DeclareVars
  161. # only calculate version once
  162. StrCmp $__WINVERV "" _winver_noveryet
  163. Return
  164. _winver_noveryet:
  165. # push used registers on the stack
  166. Push $0
  167. Push $1 ;maj
  168. Push $2 ;min
  169. Push $3 ;bld
  170. Push $R0 ;temp
  171. # allocate memory
  172. System::Alloc ${OSVERSIONINFOEXA_SIZE}
  173. Pop $0
  174. # use OSVERSIONINFOEX
  175. !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOEXA_SIZE}
  176. IntCmp $3 0 "" _winver_ex _winver_ex
  177. # OSVERSIONINFOEX not allowed (Win9x or NT4 w/SP < 6), use OSVERSIONINFO
  178. !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOA_SIZE}
  179. _winver_ex:
  180. # get results from struct
  181. System::Call '*$0(i.s,i.r1,i.r2,i.r3,i.s,&t128.s,&i2.s,&i2,&i2,&i1.s,&i1)'
  182. # free struct
  183. System::Free $0
  184. # win9x has major and minor info in high word of dwBuildNumber - remove it
  185. IntOp $3 $3 & 0xFFFF
  186. # get dwOSVersionInfoSize
  187. Pop $R0
  188. # get dwPlatformId
  189. Pop $0
  190. # NT?
  191. IntCmp $0 ${VER_PLATFORM_WIN32_NT} "" _winver_notnt _winver_notnt
  192. IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTBIT}
  193. IntOp $__WINVERV $__WINVERV | ${_WINVER_NTBIT}
  194. _winver_notnt:
  195. # get service pack information
  196. IntCmp $0 ${VER_PLATFORM_WIN32_NT} _winver_nt "" _winver_nt # win9x
  197. # get szCSDVersion
  198. Pop $0
  199. # copy second char
  200. StrCpy $0 $0 1 1
  201. # discard invalid wServicePackMajor and wProductType
  202. Pop $R0
  203. Pop $R0
  204. # switch
  205. StrCmp $0 'A' "" +3
  206. StrCpy $0 1
  207. Goto _winver_sp_done
  208. StrCmp $0 'B' "" +3
  209. StrCpy $0 2
  210. Goto _winver_sp_done
  211. StrCmp $0 'C' "" +3
  212. StrCpy $0 3
  213. Goto _winver_sp_done
  214. StrCpy $0 0
  215. Goto _winver_sp_done
  216. _winver_nt: # nt
  217. IntCmp $R0 ${OSVERSIONINFOEXA_SIZE} "" _winver_sp_noex _winver_sp_noex
  218. # discard szCSDVersion
  219. Pop $0
  220. # get wProductType
  221. Exch
  222. Pop $0
  223. # is server?
  224. IntCmp $0 ${VER_NT_WORKSTATION} _winver_noserver _winver_noserver ""
  225. IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTSRVBIT}
  226. _winver_noserver:
  227. # get wServicePackMajor
  228. Pop $0
  229. # done with sp
  230. Goto _winver_sp_done
  231. _winver_sp_noex: # OSVERSIONINFO, not OSVERSIONINFOEX
  232. #### TODO
  233. ## For IsServer to support < NT4SP6, we need to check the registry
  234. ## here to see if we are a server and/or DC
  235. # get szCSDVersion
  236. Pop $0
  237. # discard invalid wServicePackMajor and wProductType
  238. Pop $R0
  239. Pop $R0
  240. # get service pack number from text
  241. StrCpy $R0 $0 13
  242. StrCmp $R0 "Service Pack " "" +3
  243. StrCpy $0 $0 "" 13 # cut "Service Pack "
  244. Goto +2
  245. StrCpy $0 0 # no service pack
  246. !ifdef WINVER_NT4_OVER_W95
  247. IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
  248. !endif
  249. _winver_sp_done:
  250. # store service pack
  251. IntOp $0 $0 << 16
  252. IntOp $__WINVERSP $__WINVERSP | $0
  253. ### now for the version
  254. # is server?
  255. IntOp $0 $__WINVERSP & ${_WINVER_NTSRVBIT}
  256. # windows xp x64?
  257. IntCmp $0 0 "" _winver_not_xp_x64 _winver_not_xp_x64 # not server
  258. IntCmp $1 5 "" _winver_not_xp_x64 _winver_not_xp_x64 # maj 5
  259. IntCmp $2 2 "" _winver_not_xp_x64 _winver_not_xp_x64 # min 2
  260. # change XP x64 from 5.2 to 5.1 so it's still XP
  261. StrCpy $2 1
  262. _winver_not_xp_x64:
  263. # server 2008?
  264. IntCmp $0 0 _winver_not_2008 # server
  265. IntCmp $1 6 "" _winver_not_2008 _winver_not_2008 # maj 6
  266. IntCmp $2 0 "" _winver_not_2008 _winver_not_2008 # min 0
  267. # extra bit so Server 2008 comes after Vista SP1 that has the same minor version
  268. IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
  269. _winver_not_2008:
  270. # pack version
  271. IntOp $1 $1 << 24 # VerMajor
  272. IntOp $__WINVERV $__WINVERV | $1
  273. IntOp $0 $2 << 16
  274. IntOp $__WINVERV $__WINVERV | $0 # VerMinor
  275. IntOp $__WINVERSP $__WINVERSP | $3 # VerBuild
  276. # restore registers
  277. Pop $R0
  278. Pop $3
  279. Pop $2
  280. Pop $1
  281. Pop $0
  282. !macroend
  283. # version comparison LogicLib macros
  284. !macro _WinVerAtLeast _a _b _t _f
  285. !insertmacro _LOGICLIB_TEMP
  286. ${CallArtificialFunction} __WinVer_InitVars
  287. IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
  288. !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  289. !macroend
  290. !macro _WinVerIs _a _b _t _f
  291. ${CallArtificialFunction} __WinVer_InitVars
  292. !insertmacro _= $__WINVERV `${_b}` `${_t}` `${_f}`
  293. !macroend
  294. !macro _WinVerAtMost _a _b _t _f
  295. !insertmacro _LOGICLIB_TEMP
  296. ${CallArtificialFunction} __WinVer_InitVars
  297. IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
  298. !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  299. !macroend
  300. !macro __WinVer_DefineOSTest Test OS Suffix
  301. !define ${Test}Win${OS} `"" WinVer${Test} ${WINVER_${OS}${Suffix}}`
  302. !macroend
  303. !macro __WinVer_DefineOSTests Test Suffix
  304. !insertmacro __WinVer_DefineOSTest ${Test} 95 '${Suffix}'
  305. !insertmacro __WinVer_DefineOSTest ${Test} 98 '${Suffix}'
  306. !insertmacro __WinVer_DefineOSTest ${Test} ME '${Suffix}'
  307. !insertmacro __WinVer_DefineOSTest ${Test} NT4 '${Suffix}'
  308. !insertmacro __WinVer_DefineOSTest ${Test} 2000 '${Suffix}'
  309. !insertmacro __WinVer_DefineOSTest ${Test} XP '${Suffix}'
  310. !insertmacro __WinVer_DefineOSTest ${Test} 2003 '${Suffix}'
  311. !insertmacro __WinVer_DefineOSTest ${Test} VISTA '${Suffix}'
  312. !insertmacro __WinVer_DefineOSTest ${Test} 2008 '${Suffix}'
  313. !macroend
  314. !insertmacro __WinVer_DefineOSTests AtLeast ""
  315. !insertmacro __WinVer_DefineOSTests Is _NT
  316. !insertmacro __WinVer_DefineOSTests AtMost ""
  317. # version feature LogicLib macros
  318. !macro _IsNT _a _b _t _f
  319. !insertmacro _LOGICLIB_TEMP
  320. ${CallArtificialFunction} __WinVer_InitVars
  321. IntOp $_LOGICLIB_TEMP $__WINVERSP & ${_WINVER_NTBIT}
  322. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  323. !macroend
  324. !define IsNT `"" IsNT ""`
  325. !macro _IsServerOS _a _b _t _f
  326. !insertmacro _LOGICLIB_TEMP
  327. ${CallArtificialFunction} __WinVer_InitVars
  328. IntOp $_LOGICLIB_TEMP $__WINVERSP & ${_WINVER_NTSRVBIT}
  329. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  330. !macroend
  331. !define IsServerOS `"" IsServerOS ""`
  332. # service pack macros
  333. !macro _WinVer_GetServicePackLevel OUTVAR
  334. ${CallArtificialFunction} __WinVer_InitVars
  335. IntOp ${OUTVAR} $__WINVERSP & ${_WINVER_MASKSP}
  336. IntOp ${OUTVAR} ${OUTVAR} >> 16
  337. !macroend
  338. !define WinVerGetServicePackLevel '!insertmacro _WinVer_GetServicePackLevel '
  339. !macro _AtLeastServicePack _a _b _t _f
  340. !insertmacro _LOGICLIB_TEMP
  341. ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  342. !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  343. !macroend
  344. !define AtLeastServicePack `"" AtLeastServicePack`
  345. !macro _AtMostServicePack _a _b _t _f
  346. !insertmacro _LOGICLIB_TEMP
  347. ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  348. !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  349. !macroend
  350. !define AtMostServicePack `"" AtMostServicePack`
  351. !macro _IsServicePack _a _b _t _f
  352. !insertmacro _LOGICLIB_TEMP
  353. ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  354. !insertmacro _= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  355. !macroend
  356. !define IsServicePack `"" IsServicePack`
  357. # special feature LogicLib macros
  358. !macro _WinVer_SysMetricCheck m _b _t _f
  359. !insertmacro _LOGICLIB_TEMP
  360. System::Call user32::GetSystemMetrics(i${m})i.s
  361. pop $_LOGICLIB_TEMP
  362. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  363. !macroend
  364. !define IsWin2003R2 `${SM_SERVERR2} WinVer_SysMetricCheck ""`
  365. !define IsStarterEdition `${SM_STARTER} WinVer_SysMetricCheck ""`
  366. !define OSHasMediaCenter `${SM_MEDIACENTER} WinVer_SysMetricCheck ""`
  367. !define OSHasTabletSupport `${SM_TABLETPC} WinVer_SysMetricCheck ""`
  368. # version retrieval macros
  369. !macro __WinVer_GetVer var rshift mask outvar
  370. ${CallArtificialFunction} __WinVer_InitVars
  371. !if "${mask}" != ""
  372. IntOp ${outvar} ${var} & ${mask}
  373. !if "${rshift}" != ""
  374. IntOp ${outvar} ${outvar} >> ${rshift}
  375. !endif
  376. !else
  377. IntOp ${outvar} ${var} >> ${rshift}
  378. !endif
  379. !macroend
  380. !define WinVerGetMajor '!insertmacro __WinVer_GetVer $__WINVERV 24 ${_WINVER_MASKVMAJ}'
  381. !define WinVerGetMinor '!insertmacro __WinVer_GetVer $__WINVERV 16 ${_WINVER_MASKVMIN}'
  382. !define WinVerGetBuild '!insertmacro __WinVer_GetVer $__WINVERSP "" ${_WINVER_MASKVBLD}'
  383. # done
  384. !endif # !___WINVER__NSH___
  385. !verbose pop