WinVer.nsh 23 KB

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