当用户尝试在不支持的操作系统上安装时如何显示弹出消息
How to show the popup message when user tries to install on Unsupported Operating System
安装软件时,我想检测操作系统,如果是 "Windows 10 Pro" 或 "Windows Server 2012" 应该会弹出一个消息框并停止安装。
我正在使用下面的代码片段。但是这里即使操作系统是"Windows 10 Pro",也不会弹出消息框。
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "ProductName"
${If} $R0 == "Windows 10 Pro"
MessageBox MB_OK|MB_ICONQUESTION "This operating system is not supported." IDOK
Quit
${EndIf}
这是正确的方法还是有什么方法可以检测操作系统并显示消息框?
我真的不明白你为什么需要这些限制,但你开始吧:
!include WinVer.nsh
!define /IfNDef PRODUCT_PROFESSIONAL 0x00000030
!define /IfNDef PRODUCT_PROFESSIONAL_N 0x00000031
!define /IfNDef PRODUCT_PRO_WORKSTATION 0x000000A1
!define /IfNDef PRODUCT_PRO_WORKSTATION_N 0x000000A2
!define /IfNDef ERROR_INSTALL_REJECTED 1654
Function .onInit
System::Call 'KERNEL32::GetProductInfo(i6,i1,i0,i0,*i0r1)'
${WinVerGetBuild}
${If} ${IsServerOS} ; Windows Server?
${AndIf} U>= 9200 ; Server 2012?
${AndIf} U< 9600 ; and not Server 2012 R2?
Goto die_unsupported_os
${EndIf}
${If} U>= 9800 ; Windows 10?
${AndIfNot} ${IsServerOS} ; Not Windows Server?
${If} = ${PRODUCT_PROFESSIONAL}
${OrIf} = ${PRODUCT_PROFESSIONAL_N}
${OrIf} = ${PRODUCT_PRO_WORKSTATION}
${OrIf} = ${PRODUCT_PRO_WORKSTATION_N}
die_unsupported_os:
MessageBox mb_IconStop|mb_OK "Not allowed to run on this version of Windows for some reason!" /SD IDOK
SetErrorLevel ${ERROR_INSTALL_REJECTED}
Quit
${EndIf}
${EndIf}
FunctionEnd
注意:Windows Insider builds 也被识别为 Pro,所以你最终也会阻止它们。
安装软件时,我想检测操作系统,如果是 "Windows 10 Pro" 或 "Windows Server 2012" 应该会弹出一个消息框并停止安装。
我正在使用下面的代码片段。但是这里即使操作系统是"Windows 10 Pro",也不会弹出消息框。
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "ProductName"
${If} $R0 == "Windows 10 Pro"
MessageBox MB_OK|MB_ICONQUESTION "This operating system is not supported." IDOK
Quit
${EndIf}
这是正确的方法还是有什么方法可以检测操作系统并显示消息框?
我真的不明白你为什么需要这些限制,但你开始吧:
!include WinVer.nsh
!define /IfNDef PRODUCT_PROFESSIONAL 0x00000030
!define /IfNDef PRODUCT_PROFESSIONAL_N 0x00000031
!define /IfNDef PRODUCT_PRO_WORKSTATION 0x000000A1
!define /IfNDef PRODUCT_PRO_WORKSTATION_N 0x000000A2
!define /IfNDef ERROR_INSTALL_REJECTED 1654
Function .onInit
System::Call 'KERNEL32::GetProductInfo(i6,i1,i0,i0,*i0r1)'
${WinVerGetBuild}
${If} ${IsServerOS} ; Windows Server?
${AndIf} U>= 9200 ; Server 2012?
${AndIf} U< 9600 ; and not Server 2012 R2?
Goto die_unsupported_os
${EndIf}
${If} U>= 9800 ; Windows 10?
${AndIfNot} ${IsServerOS} ; Not Windows Server?
${If} = ${PRODUCT_PROFESSIONAL}
${OrIf} = ${PRODUCT_PROFESSIONAL_N}
${OrIf} = ${PRODUCT_PRO_WORKSTATION}
${OrIf} = ${PRODUCT_PRO_WORKSTATION_N}
die_unsupported_os:
MessageBox mb_IconStop|mb_OK "Not allowed to run on this version of Windows for some reason!" /SD IDOK
SetErrorLevel ${ERROR_INSTALL_REJECTED}
Quit
${EndIf}
${EndIf}
FunctionEnd
注意:Windows Insider builds 也被识别为 Pro,所以你最终也会阻止它们。