当前位置: 首页 > 文档资料 > NSIS 用户手册 >

C.5 获取 Windows 版本

优质
小牛编辑
134浏览
2023-12-01
 ; GetWindowsVersion
 ;
 ; 基于 Yazno 的函数,http://yazno.tripod.com/powerpimpit/
 ; Joost Verburg 更新
 ;
 ; 返回到堆栈顶
 ;
 ; Windows 版本 (95、98、ME、NT x.x、2000、XP、2003)
 ; 或
 ; '' (未知 Windows 版本)
 ;
 ; 用法:
 ;   Call GetWindowsVersion
 ;   Pop $R0
 ;   ; 在这里 $R0 为 "NT 4.0" 或其它
 Function GetWindowsVersion
   Push $R0
   Push $R1
   ClearErrors
   ReadRegStr $R0 HKLM \
   "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
   IfErrors 0 lbl_winnt
   ; 不是 NT
   ReadRegStr $R0 HKLM \
   "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
   StrCpy $R1 $R0 1
   StrCmp $R1 '4' 0 lbl_error
   StrCpy $R1 $R0 3
   StrCmp $R1 '4.0' lbl_win32_95
   StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98
   lbl_win32_95:
     StrCpy $R0 '95'
   Goto lbl_done
   lbl_win32_98:
     StrCpy $R0 '98'
   Goto lbl_done
   lbl_win32_ME:
     StrCpy $R0 'ME'
   Goto lbl_done
   lbl_winnt:
   StrCpy $R1 $R0 1
   StrCmp $R1 '3' lbl_winnt_x
   StrCmp $R1 '4' lbl_winnt_x
   StrCpy $R1 $R0 3
   StrCmp $R1 '5.0' lbl_winnt_2000
   StrCmp $R1 '5.1' lbl_winnt_XP
   StrCmp $R1 '5.2' lbl_winnt_2003 lbl_error
   lbl_winnt_x:
     StrCpy $R0 "NT $R0" 6
   Goto lbl_done
   lbl_winnt_2000:
     Strcpy $R0 '2000'
   Goto lbl_done
   lbl_winnt_XP:
     Strcpy $R0 'XP'
   Goto lbl_done
   lbl_winnt_2003:
     Strcpy $R0 '2003'
   Goto lbl_done
   lbl_error:
     Strcpy $R0 ''
   lbl_done:
   Pop $R1
   Exch $R0
 FunctionEnd