windowsversion.nsh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ; GetWindowsVersion 4.1 (2014-10-01)
  2. ;
  3. ; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
  4. ; Update by Joost Verburg
  5. ; Update (Macro, Define, Windows 7 detection) - John T. Haller of PortableApps.com - 2008-01-07
  6. ; Update (Windows 8 detection) - Marek Mizanin (Zanir) - 2013-02-07
  7. ; Update (Windows 8.1 detection) - John T. Haller of PortableApps.com - 2014-04-04
  8. ; Update (Windows 10 TP detection) - John T. Haller of PortableApps.com - 2014-10-01
  9. ; Got from http://nsis.sourceforge.net/Get_Windows_version
  10. ;
  11. ; Usage: ${GetWindowsVersion} $R0
  12. ;
  13. ; $R0 contains: 95, 98, ME, NT x.x, 2000, XP, 2003, Vista, 7, 8, 8.1, 10.0 or '' (for unknown)
  14. Function GetWindowsVersion
  15. Push $R0
  16. Push $R1
  17. ClearErrors
  18. ReadRegStr $R0 HKLM \
  19. "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  20. IfErrors 0 lbl_winnt
  21. ; we are not NT
  22. ReadRegStr $R0 HKLM \
  23. "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
  24. StrCpy $R1 $R0 1
  25. StrCmp $R1 '4' 0 lbl_error
  26. StrCpy $R1 $R0 3
  27. StrCmp $R1 '4.0' lbl_win32_95
  28. StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98
  29. lbl_win32_95:
  30. StrCpy $R0 '95'
  31. Goto lbl_done
  32. lbl_win32_98:
  33. StrCpy $R0 '98'
  34. Goto lbl_done
  35. lbl_win32_ME:
  36. StrCpy $R0 'ME'
  37. Goto lbl_done
  38. lbl_winnt:
  39. StrCpy $R1 $R0 1
  40. StrCmp $R1 '3' lbl_winnt_x
  41. StrCmp $R1 '4' lbl_winnt_x
  42. StrCpy $R1 $R0 3
  43. StrCmp $R1 '5.0' lbl_winnt_2000
  44. StrCmp $R1 '5.1' lbl_winnt_XP
  45. StrCmp $R1 '5.2' lbl_winnt_2003
  46. StrCmp $R1 '6.0' lbl_winnt_vista
  47. StrCmp $R1 '6.1' lbl_winnt_7
  48. StrCmp $R1 '6.2' lbl_winnt_8
  49. StrCmp $R1 '6.3' lbl_winnt_81
  50. StrCmp $R1 '6.4' lbl_winnt_10 lbl_error
  51. lbl_winnt_x:
  52. StrCpy $R0 "NT $R0" 6
  53. Goto lbl_done
  54. lbl_winnt_2000:
  55. Strcpy $R0 '2000'
  56. Goto lbl_done
  57. lbl_winnt_XP:
  58. Strcpy $R0 'XP'
  59. Goto lbl_done
  60. lbl_winnt_2003:
  61. Strcpy $R0 '2003'
  62. Goto lbl_done
  63. lbl_winnt_vista:
  64. Strcpy $R0 'Vista'
  65. Goto lbl_done
  66. lbl_winnt_7:
  67. Strcpy $R0 '7'
  68. Goto lbl_done
  69. lbl_winnt_8:
  70. Strcpy $R0 '8'
  71. Goto lbl_done
  72. lbl_winnt_81:
  73. Strcpy $R0 '8.1'
  74. Goto lbl_done
  75. lbl_winnt_10:
  76. Strcpy $R0 '10.0'
  77. Goto lbl_done
  78. lbl_error:
  79. Strcpy $R0 ''
  80. lbl_done:
  81. Pop $R1
  82. Exch $R0
  83. FunctionEnd
  84. !macro GetWindowsVersion OUTPUT_VALUE
  85. Call GetWindowsVersion
  86. Pop `${OUTPUT_VALUE}`
  87. !macroend
  88. !define GetWindowsVersion '!insertmacro "GetWindowsVersion"'