Inno Setup 檢測Windows系統版本
阿新 • • 發佈:2017-06-28
comm pan 文檔 lan window create lag info servers
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系統版本