首页 > 代码库 > Inno Setup 检测Windows系统版本

Inno Setup 检测Windows系统版本

Inno Setup 检测Windows系统版本

如果软件对系统有要求,必须安装在某些系统下,在制作安装包的时候,要检测当前系统版本是否满足要求,

以免安装过程中发生异常,或者安装后,软件运行异常,给客户的感觉就是软件有BUG,客户体验不好。

下面这个Demo是我整理的检测系统版本的代码。



1
; 脚本由 Inno Setup 脚本向导 生成! 2 ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! 3 4 #define MyAppName "我的程序" 5 #define MyAppVersion "1.5" 6 #define MyAppPublisher "我的公司" 7 #define MyAppURL "http://www.example.com/" 8 #define MyAppExeName "MyProg.exe" 9 10 [Setup] 11 ; 注: AppId的值为单独标识该应用程序。 12 ; 不要为其他安装程序使用相同的AppId值。 13 ; (生成新的GUID,点击 工具|在IDE中生成GUID。) 14 AppId={{D5A23F5E-6AE2-40E9-88A5-5D6579687632} 15 AppName={#MyAppName} 16 AppVersion={#MyAppVersion} 17 ;AppVerName={#MyAppName} {#MyAppVersion} 18 AppPublisher={#MyAppPublisher} 19 AppPublisherURL={#MyAppURL} 20 AppSupportURL={#MyAppURL} 21 AppUpdatesURL={#MyAppURL} 22 DefaultDirName={pf}\{#MyAppName} 23 DefaultGroupName={#MyAppName} 24 OutputBaseFilename=setup 25 Compression=lzma 26 SolidCompression=yes 27 28 [Languages] 29 Name: "chinesesimp"; MessagesFile: "compiler:Default.isl" 30 31 [Tasks] 32 Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1 33 34 [Files] 35 Source: "C:\MyProgramFiles\Inno Setup 5\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion 36 ; 注意: 不要在任何共享系统文件上使用“Flags: ignoreversion” 37 38 [Icons] 39 Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" 40 Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon 41 42 [Run] 43 Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, ‘&‘, ‘&&‘)}}"; Flags: nowait postinstall skipifsilent 44 45 [Code] 46 function InitializeSetup: Boolean; 47 var 48 ProductName:String;//系统名称 49 EditionID:String; //系统版本 50 CSDVersion:String; //系统Service Pack 版本 51 52 Info:String;//支持系统提示 53 S: String; //调试信息 54 begin 55 RegQueryStringValue(HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion, ProductName, ProductName); 56 RegQueryStringValue(HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion, EditionID, EditionID); 57 RegQueryStringValue(HKLM, SOFTWARE\Microsoft\Windows NT\CurrentVersion, CSDVersion, CSDVersion); 58 59 S:=ProductName:+ProductName+#13#10; 60 S:=S+EditionID:+EditionID+#13#10; 61 S:=S+CSDVersion:+CSDVersion+#13#10; 62 63 Info:= 当前系统不符合软件安装要求,请更换操作系统或使用其他服务器。 +#13#10; 64 Info:=Info+支持系统列表:+#13#10; 65 Info:=Info+Windwos 7:+#13#10; 66 Info:=Info+Ultimate/Enterprise/Professional 并且要求安装 Service Pack 1+#13#10; 67 Info:=Info+Windows 10:+#13#10; 68 Info:=Info+Enterprise/Professional+#13#10; 69 Info:=Info+Windows Server 2008 R2:+#13#10; 70 Info:=Info+Standard/Enterprise 并且要求安装 Service Pack 1+#13#10; 71 Info:=Info+Windows Server 2012 R2:+#13#10; 72 Info:=Info+Standard/Enterprise+#13#10; 73 74 //SuppressibleMsgBox(Info, mbCriticalError, MB_OK, MB_OK); 75 //ProductName:=Lowercase(ProductName); 76 //Windows 7 系统检测 77 if (Pos(Windows 7, ProductName) > 0)then 78 begin 79 if((Pos(Ultimate, EditionID) > 0) or (Pos(Enterprise, EditionID) > 0) or (Pos(Professional, EditionID) > 0)) and (Pos(Service Pack 1,CSDVersion)> 0) then 80 begin 81 //MsgBox(S,mbInformation,MB_OK); //调试输出,发布请注释掉 82 Result:=true; 83 Exit; 84 end else 85 begin 86 SuppressibleMsgBox(Info, mbCriticalError, MB_OK, MB_OK); 87 Result:=false; 88 Exit; 89 end; 90 end; 91 92 //Windows 10 系统检测 93 if (Pos(Windows 10, ProductName) > 0)then 94 begin 95 if((Pos(Enterprise, EditionID) > 0) or (Pos(Professional, EditionID)> 0))then 96 begin 97 //MsgBox(S,mbInformation,MB_OK); //调试输出,发布请注释掉 98 Result:=true; 99 Exit; 100 end else 101 begin 102 SuppressibleMsgBox(Info,mbCriticalError, MB_OK, MB_OK); 103 Result:=false; 104 Exit; 105 end; 106 end; 107 108 //Windows Server 2008 R2 sp1 系统检测 109 if (Pos(Windows Server 2008 R2, ProductName) > 0)then 110 begin 111 if((Pos(ServerEnterprise, EditionID)> 0) or (Pos(ServerStandard, EditionID)> 0)) and (Pos(Service Pack 1, CSDVersion)> 0)then 112 begin 113 //MsgBox(S,mbInformation,MB_OK); //调试输出,发布请注释掉 114 Result:=true; 115 Exit; 116 end else 117 begin 118 SuppressibleMsgBox(Info, mbCriticalError, MB_OK, MB_OK); 119 Result:=false; 120 Exit; 121 end; 122 end; 123 124 //Windows Server 2012 R2 系统检测 125 if (Pos(Windows Server 2012 R2, ProductName) > 0)then 126 begin 127 if(Pos(ServerEnterprise, EditionID)> 0) or (Pos(ServerStandard, EditionID)> 0)then 128 begin 129 //MsgBox(S,mbInformation,MB_OK); //调试输出,发布请注释掉 130 Result:=true; 131 Exit; 132 end 133 else 134 begin 135 SuppressibleMsgBox(Info, mbCriticalError, MB_OK, MB_OK); 136 Result:=false; 137 Exit; 138 end; 139 end; 140 141 SuppressibleMsgBox(Info, mbCriticalError, MB_OK, MB_OK); 142 Result := false; 143 end;

 

Inno Setup 检测Windows系统版本