1、下載Inno Setup
官網(wǎng)鏈接: link
2、新建打包文件、開始打包
1、新建打包文件
2、填寫 應(yīng)用名稱、版本號、公司名稱、公司官網(wǎng)
3、選擇安裝路徑 Custom是指定默認路徑、Program Files folder是默認C盤根目錄
4、選擇程序啟動exe文件 以及Addfolder選擇全部運行文件
5、選擇安裝前顯示文字 、安裝中、安裝后
這里我只選擇了安裝前顯示條款
6、安裝模式
管理員安裝(所有用戶均可安裝)
僅限當前用戶安裝
命令覆蓋安裝
啟動時選擇安裝模式
這里我默認管理員
7、選擇安裝語言
這里我選擇的簡體中文、默認沒有的需要自己去網(wǎng)上找語言包
8、輸出信息
輸出文件位置
打包文件名稱
打包后的文件圖標
打包文件密碼
至此不需要判斷環(huán)境的設(shè)置完成、一路點擊next就行
3、需要判斷安裝時的環(huán)境
在【Files】添加如下代碼
注意這個路徑是你自己離線環(huán)境的位置 最好放置到打包文件中 D:\Desktop\打包\DELIN_SVIEW\OutPut\VC_redist.x64.exe
。
Source: "D:\Desktop\打包\DELIN_SVIEW\OutPut\VC_redist.x64.exe";DestDir:"{tmp}";DestName:"vcredistx64.exe";Flags:ignoreversion
Source: "D:\Desktop\打包\DELIN_SVIEW\OutPut\ndp472-kb4054530-x86-x64-allos-enu.exe";DestDir:"{tmp}";DestName:"dotnet472.exe";Flags:ignoreversion
在【Code】添加如下代碼
[Code]
//vc++ 安裝環(huán)境檢查 plat:x64 x86
function IsVCPPDetected(version:string;plat:string): Boolean;
var
success: Boolean;
key,versionkey:string;
build,versionBuild:cardinal;
begin
versionkey:=version;
versionBuild:=0;
case version of
'13':
begin
versionkey:='12.0';
versionBuild:=40660;
end;
'15':
begin
versionkey:='14.0';
versionBuild:=23026;
end;
'19':
begin
versionkey:='14.0';
versionBuild:=28720;
end;
end;
key:='SOFTWARE\Wow6432Node\Microsoft\VisualStudio\'+versionkey+'\VC\Runtimes\'+plat;
success:=RegQueryDWordValue(HKLM, key, 'Bld', build);
success:=success and (build>=versionBuild);
result := success;
end;
//.net framework安裝檢查 —— 判斷指定的.NET Framework版本及service pack是否已經(jīng)安裝
// 函數(shù)參數(shù)說明:
// 參數(shù)1:version -- 指定待判斷的.NET Framework版本【下面列舉了對應(yīng)關(guān)系】:
// 'v1.1' .NET Framework 1.1
// 'v2.0' .NET Framework 2.0
// 'v3.0' .NET Framework 3.0
// 'v3.5' .NET Framework 3.5
// 'v4\Client' .NET Framework 4.0 Client Profile
// 'v4\Full' .NET Framework 4.0 Full Installation
// 'v4.5' .NET Framework 4.5
// 'v4.5.1' .NET Framework 4.5.1
// 'v4.5.2' .NET Framework 4.5.2
// 'v4.6' .NET Framework 4.6
// 'v4.6.1' .NET Framework 4.6.1
// 'v4.6.2' .NET Framework 4.6.2
// 'v4.7' .NET Framework 4.7
// 'v4.7.1' .NET Framework 4.7.1
// 'v4.7.2' .NET Framework 4.7.2
// `v4.8` .NET Framework 4.8
//
// 參數(shù)2:service -- 指定待判斷的service pack版本:
// 0 No service packs required
// 1, 2, etc. Service pack 1, 2, etc. required
function IsDotNetDetected(version: string; service: cardinal): boolean;
var
key, versionKey: string;
install, release, serviceCount, versionRelease: cardinal;
success: boolean;
begin
versionKey := version;
versionRelease := 0;
// .NET 1.1 and 2.0 embed release number in version key
if version = 'v1.1' then begin
versionKey := 'v1.1.4322';
end else if version = 'v2.0' then begin
versionKey := 'v2.0.50727';
end
// .NET 4.5 and newer install as update to .NET 4.0 Full
else if Pos('v4.', version) = 1 then begin
versionKey := 'v4\Full';
case version of
'v4.5': versionRelease := 378389;
'v4.5.1': versionRelease := 378675; // 378758 on Windows 8 and older
'v4.5.2': versionRelease := 379893;
'v4.6': versionRelease := 393295; // 393297 on Windows 8.1 and older
'v4.6.1': versionRelease := 394254; // 394271 before Win10 November Update
'v4.6.2': versionRelease := 394802; // 394806 before Win10 Anniversary Update
'v4.7': versionRelease := 460798; // 460805 before Win10 Creators Update
'v4.7.1': versionRelease := 461308; // 461310 before Win10 Fall Creators Update
'v4.7.2': versionRelease := 461808; // 461814 before Win10 April 2018 Update
'v4.8': versionRelease := 528040;
end;
end;
// installation key group for all .NET versions
key := 'SOFTWARE\Microsoft\NET Framework Setup\NDP\' + versionKey;
// .NET 3.0 uses value InstallSuccess in subkey Setup
if Pos('v3.0', version) = 1 then begin
success := RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install);
end else begin
success := RegQueryDWordValue(HKLM, key, 'Install', install);
end;
// .NET 4.0 and newer use value Servicing instead of SP
if Pos('v4', version) = 1 then begin
success := success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount);
end else begin
success := success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount);
end;
// .NET 4.5 and newer use additional value Release
if versionRelease > 0 then begin
success := success and RegQueryDWordValue(HKLM, key, 'Release', release);
success := success and (release >= versionRelease);
end;
result := success and (install = 1) and (serviceCount >= service);
end;
//安裝包初始化
function CheckDotNet(): Boolean;
var Path:string ;
ResultCode: Integer;
Success:Boolean;
begin
Success:=true;
if not IsDotNetDetected('v4.7.2', 0) then
begin
MsgBox('軟件運行需要 Microsoft .NET Framework 4.7.2, 即將開始安裝.NET Framework。', mbInformation, MB_OK);
ExtractTemporaryFile('dotnet472.exe');
Path:=ExpandConstant('{tmp}\dotnet472.exe')
Exec(Path, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
if not IsDotNetDetected('v4.7.2', 0) then
begin
if MsgBox('.Net Framework4.7.2組件安裝失敗,無法運行程序,是否繼續(xù)安裝!',mbInformation,MB_YESNO) = IDYES then
begin
Success:=true
end else
begin
Success := false;
result:=Success;
Exit;
end;
end
else
Success := true;
end
else
Success := true;
result := Success;
end;
//安裝包初始化
function CheckVC(): Boolean;
var Path:string ;
ResultCode: Integer;
Success:Boolean;
begin
Success:=true;
if not IsVCPPDetected('19','x64') then
begin
MsgBox('軟件運行需要 Microsoft Visual C++ 2019 Redistributable x64, 即將開始安裝vc redist x64', mbInformation, MB_OK);
ExtractTemporaryFile('vcredistx64.exe');
Path:=ExpandConstant('{tmp}\vcredistx64.exe')
Exec(Path, '', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);
if not IsVCPPDetected('19','x64') then
begin
if MsgBox('Microsoft Visual C++ 2019 Redistributable x64組件安裝失敗,部分功能無法使用,是否繼續(xù)安裝!',mbInformation,MB_YesNo) = IDYES then
begin
Success:=true;
end else begin
Success := false;
result:=Success;
Exit;
end;
end
else begin end;
end;
result := Success;
end;
function InitializeSetup: Boolean;
begin
Result := CheckDotNet();
Result := CheckVC();
end;
最后點擊運行即可文章來源:http://www.zghlxwxcb.cn/news/detail-599725.html
跑完就會生成.exe文件在你 第八步 指定的輸出目錄下文章來源地址http://www.zghlxwxcb.cn/news/detail-599725.html
到了這里,關(guān)于Inno Setup打包winform、wpf程序可判斷VC++和.net環(huán)境的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!