最新消息:

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

nsis 永恒心锁 2369浏览 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
免责声明:根据《计算机软件保护条例》第十七条规定“为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。”您需知晓本站所有内容资源均来源于网络,仅供用户交流学习与研究使用,版权归属原版权方所有,版权争议与本站无关,用户本人下载后不能用作商业或非法用途,需在24个小时之内从您的电脑中彻底删除上述内容,否则后果均由用户承担责任;如果您访问和下载此文件,表示您同意只将此文件用于参考、学习而非其他用途,否则一切后果请您自行承担,如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。丨本站为个人博客非盈利性站点,所有软件信息均来自网络,所有资源仅供学习参考研究目的,并不贩卖软件,不存在任何商业目的及用途。丨本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权BY-NC-SA协议进行授权

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

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