最新消息:

判断系统版本信息并写入到文件

nsis 永恒心锁 1721浏览 0评论

systeminfo.ini 的格式

[systeminfo]
WINDOWS=
X86_X64=
VERNUM=
SP= 
Language=

NSIS 源码

!include "WinVer.nsh"
!include "x64.nsh"
OutFile "systeminfo.EXE"
Name "systeminfo"
SetFont /LANG=2052 "tahoma" 8
LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"
 
Var WINS_SP ;操作系统SP数字号
Var WINDOWS_Version ;WINDOWS版本
Var Service_Pack ;SP版本
Var Kernel_version ;内核版本
Var X86_X64 ;系统位数
Var WINDOWS_Language ;WINDOWS语言
SilentInstall silent
Section
 
 ;判断系统版本
ReadRegStr $WINDOWS_Version HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion" ;读取系统版本注册表键值
StrCmp $WINDOWS_Version "" +1 +2
ReadRegStr $WINDOWS_Version HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" "VersionNumber" ;读取系统版本注册表键值
 
${If} ${RunningX64}
SetRegView 64
ReadRegStr $WINS_SP HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CSDVersion" ;读取系统SP注册表键值
strcpy $Service_Pack "$WINS_SP" "" -1 ;截取路径的后1个字符
${Else}
SetRegView 32
ReadRegStr $WINS_SP HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CSDVersion" ;读取系统SP注册表键值
strcpy $Service_Pack "$WINS_SP" "" -1 ;截取路径的后1个字符
${EndIf}
 
StrCmp $WINDOWS_Version "4.9" +1 +2
StrCpy $WINDOWS_Version "98"
StrCmp $WINDOWS_Version "5.0" +1 +2
StrCpy $WINDOWS_Version "2000"
StrCmp $WINDOWS_Version "5.1" +1 +2
StrCpy $WINDOWS_Version "XP"
StrCmp $WINDOWS_Version "5.2" +1 +2
StrCpy $WINDOWS_Version "2003"
StrCmp $WINDOWS_Version "6.0" +1 +2
StrCpy $WINDOWS_Version "Vista"
StrCmp $WINDOWS_Version "6.1" +1 +2
StrCpy $WINDOWS_Version "7"
StrCmp $WINDOWS_Version "6.2" +1 +2
StrCpy $WINDOWS_Version "8"
StrCmp $WINDOWS_Version "6.3" +1 +2
StrCpy $WINDOWS_Version "10"
;#######################################################################################################
;判断是X86还是X64
 
${If} ${AtLeastWinXP}
System::Alloc 36
pop $Kernel_version
${EndIf}
 
${If} $Kernel_version <> 0
System::Call 'kernel32::GetNativeSystemInfo(i $Kernel_version)'
System::Call "*$Kernel_version(&i2.r1)"
System::Free $Kernel_version
 
StrCmp $1 0 +1 +2
StrCpy $X86_X64 "x86"
StrCmp $1 6 +1 +2
StrCpy $X86_X64 "ia64"
StrCmp $1 9 +1 +2
StrCpy $X86_X64 "x64"
IntCmp $1 10 +1 +2 +1
StrCpy $X86_X64 "unknown"
${EndIf}
 
;从注册表中读取操作系统语言
ReadRegStr $WINDOWS_Language HKLM "SYSTEM\CurrentControlSet\Control\Nls\Language" "Default"
${If} $WINDOWS_Language = 0804
WriteINIStr "$EXEDIR\systeminfo.ini" "systeminfo" "Language" "简体中文"
${Else}
MessageBox MB_OK "只支持简体中文系统打补丁。"
Quit
 ;MessageBox MB_OK "您的操作系统语言为简体中文。"
;${ElseIf} $WINDOWS_Language == 0404
 ;MessageBox MB_OK "您的操作系统语言为繁体中文。"
;${ElseIf} $WINDOWS_Language == 0409
 ;MessageBox MB_OK "您的操作系统语言为英文。"
${EndIf}
WriteINIStr "$EXEDIR\systeminfo.ini" "systeminfo" "WINDOWS" "WIN$WINDOWS_Version"
WriteINIStr "$EXEDIR\systeminfo.ini" "systeminfo" "VERNUM" "$WINDOWS_Version"
WriteINIStr "$EXEDIR\systeminfo.ini" "systeminfo" "SP" "$Service_Pack"
WriteINIStr "$EXEDIR\systeminfo.ini" "systeminfo" "X86_X64" "$X86_X64"
SectionEnd
永恒心锁,版权所有丨如未注明,均为转载丨本网站采用BY-NC-SA协议进行授权

转载请注明:永恒心锁-分享互联网 » 判断系统版本信息并写入到文件

您必须 登录 才能发表评论!