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;
时间: 2024-08-28 22:05:48

Inno Setup 检测Windows系统版本的相关文章

Windows 系统版本判断

Windows 系统版本判断 博客分类: C/C++ 很多情况下,需要软件判断操作系统,其实网上写的都很少,我希望这篇文章能给大家帮助 首先我们要在.h中定义下面的东西 Cpp代码   #define PRODUCT_UNDEFINED                       0x00000000 #define PRODUCT_ULTIMATE                        0x00000001 #define PRODUCT_HOME_BASIC             

inno setup判断是Windows系统版本(其实还是Delphi代码,还能检查域控制器和家庭版)

1.设置Windows最低版本要求 [Setup]: MinVersion 格式: a.bb,c.dd,这里 a.bb 是 Windows 版本,c.dd 是 Windows NT 版本. 默认值: 4.0,4.0 描述:这个指令让你指定你的软件运行必须的 Windows 或 Windows NT 版本最小版本,要防止你的程序在 Windows 或 Windows NT 下运行,请在最小版本中的一个指定“0”.构建号和/或安全服务包级别可以包含在版本号中.如果用户系统不适合最小版本需求,安装程序

Inno Setup 检测已安装的.NET Framework 版本

翻译自:http://kynosarges.org/DotNetVersion.html 由 Jordan Russell 写的 Inno Setup 是一个伟大的安装脚本程序,但缺乏一个内置的函数来确定安装在目标机器上的.NET Framework版本.幸运的是,它很容易使用 Pascal 脚本语言来实现这样的功能. 脚本 在下面的 Inno Setup的 脚本代码块,函数 IsDotNetDetected 检查指定的.NET Framework 版本和至少指定的服务包级别是否被安装了.所有列

Windows系统版本判定那些事儿

v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}/* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colb

Windows系统版本型号MSDN版、OEM版、RTM版、VOL版区别

我们常常听说操作系统的MSDN版.OEM版.RTM版.VOL版等等,它们到底是什么意思,有什么不同呢? (一)MSDN (Microsoft Developer Network)版MSDN软件是微软公司面向软件开发者的一种版本.MSDN 涵盖了所有可以被开发扩充的平台和应用程序,如微软公司的百科全书 Encarta,或者是各种游戏,是不包括在 MSDN 之内的,因为这些产品直接面向最终用户,没有进行程序开发的必要.MSDN 在 Operating System 以上的等级都有附微软的软件授权,根

Inno Setup :Hello World

背景   Inno Setup 是Windows下的一个免费的安装制作软件,小巧.简便.精美是其最大特点,支持pascal脚本,能快速制作出标准Windows2000风格的安装界面,足以完成一般安装任务.该软件用Delphi写成,其官方网站同时也提供源程序免费下载.它虽不能与Installshield这类恐龙级的安装制作软件相比,但也当之无愧算是后起之秀.  工作中需要将项目打包成安装包,选择使用Inno Setup.  Inno Setup自己下载安装,网址:http://www.jrsoft

使用bat脚本永久激活Windows系统

每次重装完系统后,右下角会提示系统未激活,无法进行一些个性化设置. 在这里我自己写了一个bat脚本用于激活Windows系统.(仅供学习) 文件下载: 链接:https://pan.baidu.com/s/1mCdeQMSZiBWcRNsUhIjPXw 提取码:myk3 这里有三个文件: WindosActive.bat是脚本命令,需要以管理员身份运行. WindosSerial.ini 是windows激活密钥,我已经内置了一些密钥,如果我内置的没有激活你的系统,大家可以自己百度对应的Wind

使用bat脚本永久激活Windows系统(摘抄)

使用bat脚本永久激活Windows系统 每次重装完系统后,右下角会提示系统未激活,无法进行一些个性化设置. 在这里我自己写了一个bat脚本用于激活Windows系统.(仅供学习) 文件下载: 链接:https://pan.baidu.com/s/16KmpO6Ir51nYcp5xJIzzvA 提取码:vzhs 这里有三个文件: WindowsActive.bat是脚本命令,需要以管理员身份运行. WindowsSerial.ini 是windows激活密钥,我已经内置了一些密钥,如果我内置的没

golang---获取windows系统相关信息

package main import ( "fmt" "net" "runtime" "strings" "syscall" "time" "unsafe" "github.com/StackExchange/wmi" ) var ( advapi = syscall.NewLazyDLL("Advapi32.dll") ke