WinVer.nsh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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. ; IsServerOS checks if the installer is running on a server version of Windows (2000, 2003, 2008, etc.)
  16. ; IsDomainController checks if the server is a domain controller
  17. ;
  18. ; AtLeastWin<version> checks if the installer is running on Windows version at least as specified.
  19. ; IsWin<version> checks if the installer is running on Windows version exactly as specified.
  20. ; AtMostWin<version> checks if the installer is running on Windows version at most as specified.
  21. ; AtLeastBuild <number> checks if the installer is running on a Windows version with a minimum build number.
  22. ; AtMostBuild <number> checks if the installer is running on a Windows version with a maximum build number.
  23. ; AtLeastWaaS <name> and AtMostWaaS <name> checks Windows 10 "friendly names" against the build number.
  24. ;
  25. ; <version> can be replaced with the following values:
  26. ;
  27. ; 95
  28. ; 98
  29. ; ME
  30. ;
  31. ; NT4
  32. ; 2000
  33. ; XP
  34. ; 2003
  35. ; Vista
  36. ; 2008
  37. ; 7
  38. ; 2008R2
  39. ; 8
  40. ; 2012
  41. ; 8.1
  42. ; 2012R2
  43. ; 10
  44. ;
  45. ; Note: Windows 8.1 and later will be detected as Windows 8 unless ManifestSupportedOS is set correctly!
  46. ;
  47. ; AtLeastServicePack checks if the installer is running on Windows service pack version at least as specified.
  48. ; IsServicePack checks if the installer is running on Windows service pack version exactly as specified.
  49. ; AtMostServicePack checks if the installer is running on Windows service version pack at most as specified.
  50. ;
  51. ; Usage examples:
  52. ;
  53. ; ${If} ${IsNT}
  54. ; DetailPrint "Running on NT family."
  55. ; DetailPrint "Surely not running on 95, 98 or ME."
  56. ; ${AndIf} ${AtLeastWinNT4}
  57. ; DetailPrint "Running on NT4 or better. Could even be 2003."
  58. ; ${EndIf}
  59. ;
  60. ; ${If} ${AtLeastWinXP}
  61. ; DetailPrint "Running on XP or better."
  62. ; ${EndIf}
  63. ;
  64. ; ${If} ${IsWin2000}
  65. ; DetailPrint "Running on 2000."
  66. ; ${EndIf}
  67. ;
  68. ; ${If} ${IsWin2000}
  69. ; ${AndIf} ${AtLeastServicePack} 3
  70. ; ${OrIf} ${AtLeastWinXP}
  71. ; DetailPrint "Running Win2000 SP3 or above"
  72. ; ${EndIf}
  73. ;
  74. ; ${If} ${AtMostWinXP}
  75. ; DetailPrint "Running on XP or older. Surely not running on Vista. Maybe 98, or even 95."
  76. ; ${EndIf}
  77. ;
  78. ; Warning:
  79. ;
  80. ; Windows 95 and NT both use the same version number. To avoid getting NT4 misidentified
  81. ; as Windows 95 and vice-versa or 98 as a version higher than NT4, always use IsNT to
  82. ; check if running on the NT family.
  83. ;
  84. ; ${If} ${AtLeastWin95}
  85. ; ${AndIf} ${AtMostWinME}
  86. ; DetailPrint "Running 95, 98 or ME."
  87. ; DetailPrint "Actually, maybe it's NT4?"
  88. ; ${If} ${IsNT}
  89. ; DetailPrint "Yes, it's NT4! oops..."
  90. ; ${Else}
  91. ; DetailPrint "Nope, not NT4. phew..."
  92. ; ${EndIf}
  93. ; ${EndIf}
  94. ;
  95. ;
  96. ; Other useful extensions are:
  97. ;
  98. ; * IsWin2003R2
  99. ; * IsStarterEdition
  100. ; * OSHasMediaCenter
  101. ; * OSHasTabletSupport
  102. ;
  103. !verbose push
  104. !verbose 3
  105. !ifndef ___WINVER__NSH___
  106. !define ___WINVER__NSH___
  107. !include LogicLib.nsh
  108. !include Util.nsh
  109. # masks for our variables
  110. !define _WINVER_VERXBIT 0x00000001 ; Used to boost $__WINVERV
  111. !define _WINVER_MASKVMAJ 0x7F000000 ; $__WINVERV mask
  112. !define _WINVER_MASKVMIN 0x00FF0000 ; $__WINVERV mask
  113. !define _WINVER_NTMASK 0x7FFFFFFF ; $__WINVERV mask used by AtMost/AtLeast
  114. !define _WINVER_NTBIT 0x80000000 ; $__WINVERV bit used by Is and $__WINVERSP bit used by IsNT
  115. !define _WINVER_NTSRVBIT 0x40000000 ; $__WINVERSP bit for !VER_NT_WORKSTATION
  116. !define _WINVER_NTDCBIT 0x20000000 ; $__WINVERSP bit for VER_NT_DOMAIN_CONTROLLER
  117. !define _WINVER_MASKVBLD 0x0000FFFF ; $__WINVERSP mask for OS build number
  118. !define _WINVER_MASKSP 0x000F0000 ; $__WINVERSP mask for OS service pack
  119. # possible variable values for different versions
  120. !define WINVER_95_NT 0x04000000 ;4.00.0950
  121. !define WINVER_95 0x04000000 ;4.00.0950
  122. !define WINVER_98_NT 0x040a0000 ;4.10.1998
  123. !define WINVER_98 0x040a0000 ;4.10.1998
  124. ;define WINVER_98SE 0x040a0000 ;4.10.2222
  125. !define WINVER_ME_NT 0x045a0000 ;4.90.3000
  126. !define WINVER_ME 0x045a0000 ;4.90.3000
  127. ;define WINVER_NT3.51 ;3.51.1057
  128. !define WINVER_NT4_NT 0x84000000 ;4.00.1381
  129. !define WINVER_NT4 0x04000000 ;4.00.1381
  130. !define WINVER_2000_NT 0x85000000 ;5.00.2195
  131. !define WINVER_2000 0x05000000 ;5.00.2195
  132. !define WINVER_XP_NT 0x85010000 ;5.01.2600
  133. !define WINVER_XP 0x05010000 ;5.01.2600
  134. ;define WINVER_XP64 ;5.02.3790
  135. !define WINVER_2003_NT 0x85020000 ;5.02.3790
  136. !define WINVER_2003 0x05020000 ;5.02.3790
  137. !define WINVER_VISTA_NT 0x86000000 ;6.00.6000
  138. !define WINVER_VISTA 0x06000000 ;6.00.6000
  139. !define WINVER_2008_NT 0x86000001 ;6.00.6001
  140. !define WINVER_2008 0x06000001 ;6.00.6001
  141. !define WINVER_7_NT 0x86010000 ;6.01.7600
  142. !define WINVER_7 0x06010000 ;6.01.7600
  143. !define WINVER_2008R2_NT 0x86010001 ;6.01.7600
  144. !define WINVER_2008R2 0x06010001 ;6.01.7600
  145. !define WINVER_8_NT 0x86020000 ;6.02.9200
  146. !define WINVER_8 0x06020000 ;6.02.9200
  147. !define WINVER_2012_NT 0x86020001 ;6.02.9200
  148. !define WINVER_2012 0x06020001 ;6.02.9200
  149. !define WINVER_8.1_NT 0x86030000 ;6.03.9600
  150. !define WINVER_8.1 0x06030000 ;6.03.9600
  151. !define WINVER_2012R2_NT 0x86030001 ;6.03.9600
  152. !define WINVER_2012R2 0x06030001 ;6.03.9600
  153. !define WINVER_10_NT 0x8A000000 ;10.0.10240
  154. !define WINVER_10 0x0A000000 ;10.0.10240
  155. !define WINVER_2016_NT 0x8A000001 ;10.0.14393
  156. !define WINVER_2016 0x0A000001 ;10.0.14393
  157. # use this to make all nt > 9x
  158. !ifdef WINVER_NT4_OVER_W95
  159. !define /redef /math WINVER_NT4 ${WINVER_NT4} | ${_WINVER_VERXBIT}
  160. !endif
  161. # some definitions from header files
  162. !define OSVERSIONINFOW_SIZE 276
  163. !define OSVERSIONINFOEXW_SIZE 284
  164. !define OSVERSIONINFOA_SIZE 148
  165. !define OSVERSIONINFOEXA_SIZE 156
  166. !define /ifndef VER_PLATFORM_WIN32_NT 2
  167. !define /ifndef VER_NT_WORKSTATION 1
  168. !define /ifndef VER_NT_DOMAIN_CONTROLLER 2
  169. !define /ifndef VER_NT_SERVER 3
  170. !define SM_TABLETPC 86
  171. !define SM_MEDIACENTER 87
  172. !define SM_STARTER 88
  173. !define SM_SERVERR2 89
  174. # variable declaration
  175. !macro __WinVer_DeclareVars
  176. !ifndef __WINVER_VARS_DECLARED
  177. !define __WINVER_VARS_DECLARED
  178. Var /GLOBAL __WINVERV
  179. Var /GLOBAL __WINVERSP
  180. !endif
  181. !macroend
  182. !macro __WinVer_Optimize
  183. !ifndef __WINVER_NOOPTIMIZE
  184. !if "${NSIS_CHAR_SIZE}" > 1
  185. !define /ReDef AtMostWin95 '"" LogicLib_AlwaysFalse ""'
  186. !define /ReDef AtMostWin98 '"" LogicLib_AlwaysFalse ""'
  187. !define /ReDef AtMostWinME '"" LogicLib_AlwaysFalse ""'
  188. !define /ReDef IsWin95 '"" LogicLib_AlwaysFalse ""'
  189. !define /ReDef IsWin98 '"" LogicLib_AlwaysFalse ""'
  190. !define /ReDef IsWinME '"" LogicLib_AlwaysFalse ""'
  191. !endif
  192. !if "${NSIS_PTR_SIZE}" > 4
  193. !define /ReDef AtMostWin95 '"" LogicLib_AlwaysFalse ""'
  194. !define /ReDef AtMostWin98 '"" LogicLib_AlwaysFalse ""'
  195. !define /ReDef AtMostWinME '"" LogicLib_AlwaysFalse ""'
  196. !define /ReDef AtMostWinNT4 '"" LogicLib_AlwaysFalse ""'
  197. !define /ReDef IsWin95 '"" LogicLib_AlwaysFalse ""'
  198. !define /ReDef IsWin98 '"" LogicLib_AlwaysFalse ""'
  199. !define /ReDef IsWinME '"" LogicLib_AlwaysFalse ""'
  200. !define /ReDef IsWinNT4 '"" LogicLib_AlwaysFalse ""'
  201. !define /ReDef AtLeastWin95 '"" LogicLib_AlwaysTrue ""'
  202. !define /ReDef AtLeastWin98 '"" LogicLib_AlwaysTrue ""'
  203. !define /ReDef AtLeastWinME '"" LogicLib_AlwaysTrue ""'
  204. !define /ReDef AtLeastWinNT4 '"" LogicLib_AlwaysTrue ""'
  205. !define /ReDef AtLeastWin2000 '"" LogicLib_AlwaysTrue ""'
  206. !endif
  207. !ifdef NSIS_ARM | NSIS_ARM32 | NSIS_ARMNT | NSIS_ARM64
  208. !define /ReDef AtMostWin2000 '"" LogicLib_AlwaysFalse ""'
  209. !define /ReDef AtMostWinXP '"" LogicLib_AlwaysFalse ""'
  210. !define /ReDef AtMostWin2003 '"" LogicLib_AlwaysFalse ""'
  211. !define /ReDef AtMostWinVista '"" LogicLib_AlwaysFalse ""'
  212. !define /ReDef AtMostWin7 '"" LogicLib_AlwaysFalse ""'
  213. !define /ReDef IsWin95 '"" LogicLib_AlwaysFalse ""'
  214. !define /ReDef IsWin98 '"" LogicLib_AlwaysFalse ""'
  215. !define /ReDef IsWinME '"" LogicLib_AlwaysFalse ""'
  216. !define /ReDef IsWinNT4 '"" LogicLib_AlwaysFalse ""'
  217. !define /ReDef IsWin2000 '"" LogicLib_AlwaysFalse ""'
  218. !define /ReDef IsWinXP '"" LogicLib_AlwaysFalse ""'
  219. !define /ReDef IsWin2003 '"" LogicLib_AlwaysFalse ""'
  220. !define /ReDef IsWinVista '"" LogicLib_AlwaysFalse ""'
  221. !define /ReDef IsWin2008 '"" LogicLib_AlwaysFalse ""'
  222. !define /ReDef IsWin7 '"" LogicLib_AlwaysFalse ""'
  223. !define /ReDef IsWin2008R2 '"" LogicLib_AlwaysFalse ""'
  224. !define /ReDef AtLeastWin95 '"" LogicLib_AlwaysTrue ""'
  225. !define /ReDef AtLeastWin98 '"" LogicLib_AlwaysTrue ""'
  226. !define /ReDef AtLeastWinME '"" LogicLib_AlwaysTrue ""'
  227. !define /ReDef AtLeastWinNT4 '"" LogicLib_AlwaysTrue ""'
  228. !define /ReDef AtLeastWin2000 '"" LogicLib_AlwaysTrue ""'
  229. !define /ReDef AtLeastWinXP '"" LogicLib_AlwaysTrue ""'
  230. !define /ReDef AtLeastWin2003 '"" LogicLib_AlwaysTrue ""'
  231. !define /ReDef AtLeastWinVista '"" LogicLib_AlwaysTrue ""'
  232. !define /ReDef AtLeastWin2008 '"" LogicLib_AlwaysTrue ""'
  233. !define /ReDef AtLeastWin7 '"" LogicLib_AlwaysTrue ""'
  234. !define /ReDef AtLeastWin2008R2 '"" LogicLib_AlwaysTrue ""'
  235. !define /ReDef AtLeastWin8 '"" LogicLib_AlwaysTrue ""'
  236. !endif
  237. !endif
  238. !macroend
  239. # lazy initialization macro
  240. !define /IfNDef __WinVer_GWV GetWinVer
  241. !macro __WinVer_InitVars_NEW
  242. !insertmacro __WinVer_DeclareVars
  243. !insertmacro __WinVer_Optimize
  244. # only calculate version once
  245. StrCmp $__WINVERV "" _winver_noveryet
  246. Return
  247. _winver_noveryet:
  248. Push $0
  249. ${__WinVer_GWV} $0 Product
  250. ${__WinVer_GWV} $__WINVERV NTDDIMajMin
  251. IntOp $__WINVERV $__WINVERV << 16 ; _WINVER_MASKVMAJ & _WINVER_MASKVMIN
  252. IntOp $__WINVERSP $0 & 2
  253. IntOp $__WINVERSP $__WINVERSP << 29 ; _WINVER_NTSRVBIT & _WINVER_NTDCBIT
  254. !ifndef NSIS_ARM64
  255. IntCmp $__WINVERSP 0 notServer
  256. IntCmpU 0x06000000 $__WINVERV "" "" not2008 ; ${If} $__WINVERV U>= 0x06000000
  257. IntCmpU 0x09000000 $__WINVERV not2008 not2008 "" ; ${AndIf} $__WINVERV U< 0x09000000
  258. IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT} ; Extra bit so Server 2008 comes after Vista SP1 that has the same minor version, same for Win7 vs 2008R2
  259. not2008:
  260. Goto endServer
  261. notServer:
  262. IntCmp $__WINVERV 0x05020000 "" notXP64 notXP64
  263. StrCpy $__WINVERV 0x05010000 ; Change XP 64-bit from 5.2 to 5.1 so it's still XP
  264. notXP64:
  265. endServer:
  266. !endif
  267. IntCmp $0 0 notNT
  268. !if "${NSIS_PTR_SIZE}" <= 4
  269. !ifdef WINVER_NT4_OVER_W95
  270. IntCmp $__WINVERV 0x04000000 "" nt4eq95 nt4eq95
  271. IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT} ; change NT 4.0.reserved.0 to 4.0.reserved.1
  272. nt4eq95:
  273. !endif
  274. !endif
  275. IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTBIT} ; _WINVER_NTBIT
  276. IntOp $__WINVERV $__WINVERV | ${_WINVER_NTBIT} ; _WINVER_NTBIT
  277. notNT:
  278. ${__WinVer_GWV} $0 Build
  279. IntOp $__WINVERSP $__WINVERSP | $0 ; _WINVER_MASKVBLD
  280. ${__WinVer_GWV} $0 ServicePack
  281. IntOp $0 $0 << 16
  282. IntOp $__WINVERSP $__WINVERSP | $0 ; _WINVER_MASKSP
  283. Pop $0
  284. !macroend
  285. !ifmacrondef __WinVer_Call_GetVersionEx
  286. !macro __WinVer_Call_GetVersionEx STRUCT_SIZE
  287. System::Call '*$0(i ${STRUCT_SIZE})'
  288. System::Call kernel32::GetVersionEx(pr0)i.r3
  289. !macroend
  290. !endif
  291. !macro __WinVer_InitVars_OLD
  292. # variables
  293. !insertmacro __WinVer_DeclareVars
  294. !insertmacro __WinVer_Optimize
  295. # only calculate version once
  296. StrCmp $__WINVERV "" _winver_noveryet
  297. Return
  298. _winver_noveryet:
  299. # push used registers on the stack
  300. Push $0
  301. Push $1 ;maj
  302. Push $2 ;min
  303. Push $3 ;bld
  304. Push $R0 ;temp
  305. # a plugin call will lock the Unicode mode, it is now safe to set the struct size
  306. !ifdef NSIS_UNICODE
  307. !define /redef OSVERSIONINFO_SIZE ${OSVERSIONINFOW_SIZE}
  308. !define /redef OSVERSIONINFOEX_SIZE ${OSVERSIONINFOEXW_SIZE}
  309. !else
  310. !define /redef OSVERSIONINFO_SIZE ${OSVERSIONINFOA_SIZE}
  311. !define /redef OSVERSIONINFOEX_SIZE ${OSVERSIONINFOEXA_SIZE}
  312. !endif
  313. # allocate memory
  314. System::Call '*(&i${OSVERSIONINFOEX_SIZE})p.r0'
  315. # use OSVERSIONINFOEX
  316. !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFOEX_SIZE}
  317. IntCmp $3 0 "" _winver_ex _winver_ex
  318. # OSVERSIONINFOEX not allowed (Win9x or NT4 w/SP < 6), use OSVERSIONINFO
  319. !insertmacro __WinVer_Call_GetVersionEx ${OSVERSIONINFO_SIZE}
  320. _winver_ex:
  321. # get results from struct
  322. System::Call '*$0(i.s,i.r1,i.r2,i.r3,i.s,&t128.s,&i2.s,&i2,&i2,&i1.s,&i1)'
  323. # free struct
  324. System::Free $0
  325. # win9x has major and minor info in high word of dwBuildNumber - remove it
  326. IntOp $3 $3 & 0xFFFF
  327. # get dwOSVersionInfoSize
  328. Pop $R0
  329. # get dwPlatformId
  330. Pop $0
  331. # NT?
  332. IntCmp $0 ${VER_PLATFORM_WIN32_NT} "" _winver_notnt _winver_notnt
  333. IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTBIT}
  334. IntOp $__WINVERV $__WINVERV | ${_WINVER_NTBIT}
  335. _winver_notnt:
  336. !ifndef NSIS_UNICODE
  337. !if "${NSIS_PTR_SIZE}" <= 4
  338. # get service pack information
  339. IntCmp $0 ${VER_PLATFORM_WIN32_NT} _winver_nt "" _winver_nt # win9x
  340. # get szCSDVersion
  341. Pop $0
  342. # copy second char
  343. StrCpy $0 $0 1 1
  344. # discard invalid wServicePackMajor and wProductType
  345. Pop $R0
  346. Pop $R0
  347. # switch
  348. StrCmp $0 'A' "" +3
  349. StrCpy $0 1
  350. Goto _winver_sp_done
  351. StrCmp $0 'B' "" +3
  352. StrCpy $0 2
  353. Goto _winver_sp_done
  354. StrCmp $0 'C' "" +3
  355. StrCpy $0 3
  356. Goto _winver_sp_done
  357. StrCpy $0 0
  358. Goto _winver_sp_done
  359. _winver_nt: # nt
  360. !endif #~ 32-bit
  361. !endif #~ ANSI
  362. IntCmp $R0 ${OSVERSIONINFOEX_SIZE} "" _winver_sp_noex _winver_sp_noex
  363. # discard szCSDVersion
  364. Pop $0
  365. # get wProductType
  366. Exch
  367. Pop $0
  368. # is server?
  369. IntCmp $0 ${VER_NT_WORKSTATION} _winver_nt_notsrv
  370. IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTSRVBIT}
  371. IntCmp $0 ${VER_NT_DOMAIN_CONTROLLER} "" _winver_nt_notdc _winver_nt_notdc
  372. IntOp $__WINVERSP $__WINVERSP | ${_WINVER_NTDCBIT}
  373. _winver_nt_notdc:
  374. _winver_nt_notsrv:
  375. # get wServicePackMajor
  376. Pop $0
  377. # done with sp
  378. Goto _winver_sp_done
  379. _winver_sp_noex: # OSVERSIONINFO, not OSVERSIONINFOEX
  380. #### TODO
  381. ## For IsServerOS to support < NT4SP6, we need to check the registry
  382. ## here to see if we are a server and/or DC
  383. # get szCSDVersion
  384. Pop $0
  385. # discard invalid wServicePackMajor and wProductType
  386. Pop $R0
  387. Pop $R0
  388. # get service pack number from text
  389. StrCpy $R0 $0 13
  390. StrCmp $R0 "Service Pack " "" +3
  391. StrCpy $0 $0 "" 13 # cut "Service Pack "
  392. Goto +2
  393. StrCpy $0 0 # no service pack
  394. !ifdef WINVER_NT4_OVER_W95
  395. IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT} ; change NT 4.0.reserved.0 to 4.0.reserved.1
  396. !endif
  397. _winver_sp_done:
  398. # store service pack
  399. IntOp $0 $0 << 16
  400. IntOp $__WINVERSP $__WINVERSP | $0
  401. ### now for the version
  402. # is server?
  403. IntOp $0 $__WINVERSP & ${_WINVER_NTSRVBIT}
  404. # windows xp x64?
  405. IntCmp $0 0 "" _winver_not_xp_x64 _winver_not_xp_x64 # not server
  406. IntCmp $1 5 "" _winver_not_xp_x64 _winver_not_xp_x64 # maj 5
  407. IntCmp $2 2 "" _winver_not_xp_x64 _winver_not_xp_x64 # min 2
  408. # change XP x64 from 5.2 to 5.1 so it's still XP
  409. StrCpy $2 1
  410. _winver_not_xp_x64:
  411. # server 2008?
  412. IntCmp $0 0 _winver_not_ntserver # server
  413. IntCmp 6 $1 "" "" _winver_not_ntserver # maj 6
  414. # extra bit so Server 2008 comes after Vista SP1 that has the same minor version, same for Win7 vs 2008R2
  415. IntOp $__WINVERV $__WINVERV | ${_WINVER_VERXBIT}
  416. _winver_not_ntserver:
  417. # pack version
  418. IntOp $1 $1 << 24 # VerMajor
  419. IntOp $__WINVERV $__WINVERV | $1
  420. IntOp $0 $2 << 16
  421. IntOp $__WINVERV $__WINVERV | $0 # VerMinor
  422. IntOp $__WINVERSP $__WINVERSP | $3 # VerBuild
  423. # restore registers
  424. Pop $R0
  425. Pop $3
  426. Pop $2
  427. Pop $1
  428. Pop $0
  429. !macroend
  430. !macro __WinVer_InitVars
  431. !ifndef WinVer_v3_7
  432. !insertmacro __WinVer_InitVars_NEW
  433. !else
  434. !insertmacro __WinVer_InitVars_OLD
  435. !endif
  436. !macroend
  437. # version comparison LogicLib macros
  438. !macro _WinVerAtLeast _a _b _t _f
  439. !insertmacro _LOGICLIB_TEMP
  440. ${CallArtificialFunction} __WinVer_InitVars
  441. IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
  442. !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  443. !macroend
  444. !macro _WinVerIs _a _b _t _f
  445. ${CallArtificialFunction} __WinVer_InitVars
  446. !insertmacro _= $__WINVERV `${_b}` `${_t}` `${_f}`
  447. !macroend
  448. !macro _WinVerAtMost _a _b _t _f
  449. !insertmacro _LOGICLIB_TEMP
  450. ${CallArtificialFunction} __WinVer_InitVars
  451. IntOp $_LOGICLIB_TEMP $__WINVERV & ${_WINVER_NTMASK}
  452. !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  453. !macroend
  454. !macro __WinVer_DefineOSTest Test OS Suffix
  455. !define ${Test}Win${OS} `"" WinVer${Test} ${WINVER_${OS}${Suffix}}`
  456. !macroend
  457. !macro __WinVer_DefineOSTests Test Suffix
  458. !insertmacro __WinVer_DefineOSTest ${Test} 95 '${Suffix}'
  459. !insertmacro __WinVer_DefineOSTest ${Test} 98 '${Suffix}'
  460. !insertmacro __WinVer_DefineOSTest ${Test} ME '${Suffix}'
  461. !insertmacro __WinVer_DefineOSTest ${Test} NT4 '${Suffix}'
  462. !insertmacro __WinVer_DefineOSTest ${Test} 2000 '${Suffix}'
  463. !insertmacro __WinVer_DefineOSTest ${Test} XP '${Suffix}'
  464. !insertmacro __WinVer_DefineOSTest ${Test} 2003 '${Suffix}'
  465. !insertmacro __WinVer_DefineOSTest ${Test} VISTA '${Suffix}'
  466. !insertmacro __WinVer_DefineOSTest ${Test} 2008 '${Suffix}'
  467. !insertmacro __WinVer_DefineOSTest ${Test} 7 '${Suffix}'
  468. !insertmacro __WinVer_DefineOSTest ${Test} 2008R2 '${Suffix}'
  469. !insertmacro __WinVer_DefineOSTest ${Test} 8 '${Suffix}'
  470. !insertmacro __WinVer_DefineOSTest ${Test} 2012 '${Suffix}'
  471. !insertmacro __WinVer_DefineOSTest ${Test} 8.1 '${Suffix}'
  472. !insertmacro __WinVer_DefineOSTest ${Test} 2012R2 '${Suffix}'
  473. !insertmacro __WinVer_DefineOSTest ${Test} 10 '${Suffix}'
  474. !insertmacro __WinVer_DefineOSTest ${Test} 2016 '${Suffix}'
  475. !macroend
  476. !insertmacro __WinVer_DefineOSTests AtLeast ""
  477. !insertmacro __WinVer_DefineOSTests Is _NT
  478. !insertmacro __WinVer_DefineOSTests AtMost ""
  479. # version feature LogicLib macros
  480. !macro __WinVer_LL_IsBitSet _v _b _t _f
  481. !insertmacro _LOGICLIB_TEMP
  482. ${CallArtificialFunction} __WinVer_InitVars
  483. IntOp $_LOGICLIB_TEMP ${_v} & ${_b}
  484. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  485. !macroend
  486. !define IsNT `$__WINVERSP _WinVer_LL_IsBitSet ${_WINVER_NTBIT}`
  487. !define IsServerOS `$__WINVERSP _WinVer_LL_IsBitSet ${_WINVER_NTSRVBIT}`
  488. !define IsDomainController `$__WINVERSP _WinVer_LL_IsBitSet ${_WINVER_NTDCBIT}`
  489. # service pack macros
  490. !macro _WinVer_GetServicePackLevel OUTVAR
  491. !ifndef WinVer_v3_7
  492. ${__WinVer_GWV} ${OUTVAR} ServicePack
  493. !else
  494. ${CallArtificialFunction} __WinVer_InitVars
  495. IntOp ${OUTVAR} $__WINVERSP & ${_WINVER_MASKSP}
  496. IntOp ${OUTVAR} ${OUTVAR} >> 16
  497. !endif
  498. !macroend
  499. !define WinVerGetServicePackLevel '!insertmacro _WinVer_GetServicePackLevel '
  500. !macro _AtLeastServicePack _a _b _t _f
  501. !insertmacro _LOGICLIB_TEMP
  502. ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  503. !insertmacro _>= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  504. !macroend
  505. !define AtLeastServicePack `"" AtLeastServicePack`
  506. !macro _AtMostServicePack _a _b _t _f
  507. !insertmacro _LOGICLIB_TEMP
  508. ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  509. !insertmacro _<= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  510. !macroend
  511. !define AtMostServicePack `"" AtMostServicePack`
  512. !macro _IsServicePack _a _b _t _f
  513. !insertmacro _LOGICLIB_TEMP
  514. ${WinVerGetServicePackLevel} $_LOGICLIB_TEMP
  515. !insertmacro _= $_LOGICLIB_TEMP `${_b}` `${_t}` `${_f}`
  516. !macroend
  517. !define IsServicePack `"" IsServicePack`
  518. # special feature LogicLib macros
  519. !macro _WinVer_SysMetricCheck m _b _t _f
  520. !insertmacro _LOGICLIB_TEMP
  521. System::Call user32::GetSystemMetrics(i${m})i.s
  522. pop $_LOGICLIB_TEMP
  523. !insertmacro _!= $_LOGICLIB_TEMP 0 `${_t}` `${_f}`
  524. !macroend
  525. !define IsWin2003R2 `${SM_SERVERR2} WinVer_SysMetricCheck ""`
  526. !define IsStarterEdition `${SM_STARTER} WinVer_SysMetricCheck ""`
  527. !define OSHasMediaCenter `${SM_MEDIACENTER} WinVer_SysMetricCheck ""`
  528. !define OSHasTabletSupport `${SM_TABLETPC} WinVer_SysMetricCheck ""`
  529. !define IsSafeBootMode `67 WinVer_SysMetricCheck ""`
  530. # version retrieval macros
  531. !macro __WinVer_GetVer var rshift mask outvar
  532. ${CallArtificialFunction} __WinVer_InitVars
  533. !if "${mask}" != ""
  534. IntOp ${outvar} ${var} & ${mask}
  535. !if "${rshift}" != ""
  536. IntOp ${outvar} ${outvar} >> ${rshift}
  537. !endif
  538. !else
  539. IntOp ${outvar} ${var} >> ${rshift}
  540. !endif
  541. !macroend
  542. !define WinVerGetMajor '!insertmacro __WinVer_GetVer $__WINVERV 24 ${_WINVER_MASKVMAJ}'
  543. !define WinVerGetMinor '!insertmacro __WinVer_GetVer $__WINVERV 16 ${_WINVER_MASKVMIN}'
  544. !ifndef WinVer_v3_7
  545. !macro __WinVer_GetVerBuild outvar
  546. ${__WinVer_GWV} ${outvar} Build
  547. !macroend
  548. !define WinVerGetBuild '!insertmacro __WinVer_GetVerBuild '
  549. !else
  550. !define WinVerGetBuild '!insertmacro __WinVer_GetVer $__WINVERSP "" ${_WINVER_MASKVBLD}'
  551. !endif
  552. !macro _WinVer_BuildNumCheck op num _t _f
  553. !insertmacro _LOGICLIB_TEMP
  554. ${WinVerGetBuild} $_LOGICLIB_TEMP
  555. !insertmacro _${op} $_LOGICLIB_TEMP ${num} `${_t}` `${_f}`
  556. !macroend
  557. !define AtLeastBuild `U>= WinVer_BuildNumCheck `
  558. !define AtMostBuild `U<= WinVer_BuildNumCheck `
  559. # Windows as a Service macros
  560. !macro WinVer_WaaS id build fu codename marketingname
  561. !if "${id}" == ${fu}
  562. !define WinVer_WaaS_Build ${build}
  563. !else if "${id}" == "${codename}"
  564. !define WinVer_WaaS_Build ${build}
  565. !else if "${id}" == "${marketingname}"
  566. !define WinVer_WaaS_Build ${build}
  567. !endif
  568. !macroend
  569. !macro _WinVer_WaaS op id _t _f
  570. !insertmacro WinVer_WaaS "${id}" 10240 1507 "Threshold" "RTM" ; 10240.16384
  571. !insertmacro WinVer_WaaS "${id}" 10586 1511 "Threshold 2" "November Update" ; 10586.0?
  572. !insertmacro WinVer_WaaS "${id}" 14393 1607 "Redstone" "Anniversary Update" ; 14393.10
  573. !insertmacro WinVer_WaaS "${id}" 15063 1703 "Redstone 2" "Creators Update" ; 15063.13
  574. !insertmacro WinVer_WaaS "${id}" 16299 1709 "Redstone 3" "Fall Creators Update" ; 16299.19
  575. !insertmacro WinVer_WaaS "${id}" 17134 1803 "Redstone 4" "April 2018 Update" ; 17134.1
  576. !insertmacro WinVer_WaaS "${id}" 17763 1809 "Redstone 5" "October 2018 Update" ; 17763.1
  577. !insertmacro WinVer_WaaS "${id}" 18362 1903 "19H1" "May 2019 Update" ; 18362.116
  578. !insertmacro WinVer_WaaS "${id}" 18363 1909 "19H2" "November 2019 Update" ; 18363.418
  579. !insertmacro WinVer_WaaS "${id}" 19041 2004 "20H1" "May 2020 Update" ; 19041.264?
  580. !insertmacro WinVer_WaaS "${id}" 19042 20H2 "20H2" "October 2020 Update" ; 19042.572? A.K.A. 2009
  581. !insertmacro WinVer_WaaS "${id}" 19043 21H1 "21H1" "May 2021 Update" ; 19043.928
  582. !ifmacrodef WinVerExternal_WaaS_MapToBuild
  583. !insertmacro WinVerExternal_WaaS_MapToBuild ${op} "${id}" WinVer_WaaS_Build
  584. !endif
  585. !define /IfNDef WinVer_WaaS_Build 0
  586. !if "${WinVer_WaaS_Build}" <= 9600
  587. !error 'WinVer: Unknown WaaS name: ${id}'
  588. !endif
  589. !insertmacro _WinVer_BuildNumCheck ${op} ${WinVer_WaaS_Build} `${_t}` `${_f}`
  590. !undef WinVer_WaaS_Build
  591. !macroend
  592. !define AtLeastWaaS `U>= WinVer_WaaS `
  593. !define AtMostWaaS `U<= WinVer_WaaS `
  594. !endif # !___WINVER__NSH___
  595. !verbose pop