info setup製作安裝包

一 安裝包製作

  1. 準備好可執行的應用程序
  2. 下載info setup軟件 (下載地址:http://www.jrsoftware.org/isdl.php#stable
  3. 編輯腳本,生成exe https://www.cnblogs.com/linuxAndMcu/p/10974927.html

二 走過的坑

  • 生成 安裝程序.exe,雙擊開始安裝 ,但是安裝完成後點擊界面生成的可執行程序會提示少庫, 通過可執行程序找到路徑下的原來的可執行程序,雙擊可以正常運行,查看是因爲在安裝exe時,會默認在路徑下面創建一個exe,(直接把原來的exe拷貝過來),所以在執行應用程序的時候,可執行程序會按照原來的路徑依賴關係去查找庫,查找不到就會提示找不到庫,找不到資源文件。

需要設置運行程序的路徑:

; Script generated by the Inno Setup Script Wizard.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!



#define MyAppName "Test"

#define MyAppVersion "2020.0115"

#define MyAppPublisher "mycompany.Inc."

#define MyAppURL "http://www.mycompany.com/"

#define MyAppExeName "Tesy.exe"



[Setup]

; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.

; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)

AppId={{5DEDA9C7-6A3D-4898-AB9B-5B5BEEC15922}

AppName={#MyAppName}

AppVersion={#MyAppVersion}

;AppVerName={#MyAppName} {#MyAppVersion}

AppPublisher={#MyAppPublisher}

AppPublisherURL={#MyAppURL}

AppSupportURL={#MyAppURL}

AppUpdatesURL={#MyAppURL}

DefaultDirName={autopf}\{#MyAppName}

DisableProgramGroupPage=yes

; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.

UsedUserAreasWarning=no

; Uncomment the following line to run in non administrative install mode (install for current user only.)

;PrivilegesRequired=lowest

OutputDir=D:\output

OutputBaseFilename=Test
SetupIconFile=D:\work\Test\Test\Test.ico

Compression=lzma

SolidCompression=yes

WizardStyle=modern



[Languages]

Name: "english"; MessagesFile: "compiler:Default.isl"



[Tasks]

Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode


[Files]

Source: "D:\work\Test\Test.exe"; DestDir: "{app}"; Flags: ignoreversion

Source: "D:\work\Test\bin\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

; NOTE: Don't use "Flags: ignoreversion" on any shared system files


[Icons]
;注意下面幾個app後面的路徑, 有時候項目可能有多個文件夾, 這裏要注意可執行文件的相對位置對不對,否則可能提示少庫

Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"

;生成開始菜單卸載

Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}";WorkingDir:"{app}"

;Tasks: desktopicon 上面任務中的,生成快捷方式   

Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"; Tasks: desktopicon

[Run]

Filename: "{app}\bin\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent      


[code]

//卸載時執行

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);

begin

if CurUninstallStep = usDone then

begin

//刪除 {app} 文件夾及其中所有文件

DelTree(ExpandConstant('{app}'), True, True, True);

//卸載時清除註冊表

RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config')

end;

end;

//初始化時執行

function InitializeSetup(): Boolean;

var

Version: string;

strPath: string;

ResultCode: Integer;

begin

Result:= TRUE;

//read the version

if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',

'Version', Version) then

begin

// Successfully read the value

Version := Format('Exist the version %s,whether uninstall it?',[Version]);

if MsgBox(Version,mbConfirmation,MB_YESNO) = IDYES then

begin

//read the path

if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',

'InstallPath', strPath) then

begin

// Successfully read the value

strPath:= strPath + '\unins000.exe';

Exec(ExpandConstant(strPath), '', '', SW_SHOW,ewWaitUntilTerminated, ResultCode);

end;

end

else

Result:= FALSE;

end;

end;


[Registry]

;將安裝路徑寫入註冊表

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: createvalueifdoesntexist

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: uninsdeletekeyifempty

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppVersion}"

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: dword; ValueName: "VersionNum"; ValueData: "100"

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Release Date"; ValueData: "2019/12/10"

  • win10 安裝到最後啓動程序時報錯:creatprocess failed ,code 740 請求的操作需要提升,但是通過菜單欄和桌面快捷方式運行程序啓動正常。測試當exe使用管理員權限啓動時不會報錯。

修改Inno Setup程序, 使打包的文件以管理員權限運行:

https://blog.csdn.net/u011430225/article/details/84612690

  • 安裝界面使用中文語言

http://www.80iter.com/blog/1477623891786957

(1)在inno setup 安裝目錄下面添加中文翻譯文件 .isl

(我的查看default.isl時,發現就是中文的,但是安裝包是英文的,然後我把default.isl複製了一份,改了名字放到languages目錄下面,改了腳本之後成功了。注意如果路徑不對,也是使用的默認語言)

(2) 修改腳本語言配置(自己添加的提示語言,直接在腳本中換成中文就可以了)

[Languages]

Name: "Chinese"; MessagesFile: "compiler:Languages\Chinese.isl"

 

具體腳本:

; Script generated by the Inno Setup Script Wizard.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

;定義程序相關的信息

#define MyAppName "Test"

#define MyAppVersion "2020.0327"

#define MyAppPublisher "Mycompany.Inc."

#define MyAppURL "http://www.mycompany.com/"

#define MyAppExeName "Test.exe"



[Setup]

; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.

; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)

AppId={{5DEDA9C7-6A3D-4898-AB9B-5B5BEEC15922}

AppName={#MyAppName}

AppVersion={#MyAppVersion}

;AppVerName={#MyAppName} {#MyAppVersion}

AppPublisher={#MyAppPublisher}

AppPublisherURL={#MyAppURL}

AppSupportURL={#MyAppURL}

AppUpdatesURL={#MyAppURL}

DefaultDirName={autopf}\{#MyAppName}

DisableProgramGroupPage=yes

; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check.

UsedUserAreasWarning=no

; Uncomment the following line to run in non administrative install mode (install for current user only.)

;PrivilegesRequired=lowest

OutputDir=D:\output

OutputBaseFilename=Test

SetupIconFile=D:\work\Test\Test.ico

Compression=lzma

SolidCompression=yes

WizardStyle=modern



[Languages]

Name: "Chinese"; MessagesFile: "compiler:Languages\Chinese.isl"



[Tasks]

Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode


;exe所在文件夾

[Files]

Source: "D:\work\Test\bin\Test.exe"; DestDir: "{app}"; Flags: ignoreversion

Source: "D:\work\Test\bin\Test\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs

; NOTE: Don't use "Flags: ignoreversion" on any shared system files 


[Icons]

Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"

;生成開始菜單卸載

Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}";WorkingDir:"{app}"

;Tasks: desktopicon 上面任務中的,生成快捷方式

Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\bin\{#MyAppExeName}"; Tasks: desktopicon

[Run]

Filename: "{app}\bin\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[code]

//卸載時執行

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);

begin

if CurUninstallStep = usDone then

begin

//刪除 {app} 文件夾及其中所有文件

DelTree(ExpandConstant('{app}'), True, True, True);

//卸載時清除註冊表

RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config')

end;

end;

//初始化時執行

function InitializeSetup(): Boolean;

var

Version: string;

strPath: string;

ResultCode: Integer;

begin

Result:= TRUE;

//read the version

if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',

'Version', Version) then

begin

// Successfully read the value

Version := Format('版本 %s 已存在, 是否卸載?',[Version]);

if MsgBox(Version,mbConfirmation,MB_YESNO) = IDYES then

begin

//read the path

if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\myprogram\config',

'InstallPath', strPath) then

begin

// Successfully read the value

strPath:= strPath + '\unins000.exe';

Exec(ExpandConstant(strPath), '', '', SW_SHOW,ewWaitUntilTerminated, ResultCode);

end;

end

else

Result:= FALSE;

end;

end;

[Registry]

;將安裝路徑寫入註冊表

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: createvalueifdoesntexist

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; Flags: uninsdeletekeyifempty

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppVersion}"

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: dword; ValueName: "VersionNum"; ValueData: "100"

Root: HKCU; Subkey: "SOFTWARE\myprogram\config"; ValueType: string; ValueName: "Release Date"; ValueData: "2019/12/10"

 

  • 最近換了系統,然後又莫名奇妙出了個問題,權限的問題又出了

之前用的win7,加了固態,裝了win10系統,在win10系統上, C盤安裝了inno setup軟件,參照前面的方案修改了,然後運行的時候老是提示 無法修改 con.ini文件到C盤, 然後就用管理員權限運行, 發現這個報錯沒有了, 然而編譯生成的可執行文件老是報2 的錯誤一下子懵了,什麼情況?之前的2的方案有問題?又找到之前win7安裝的inno setup,之前安在D盤, 打開運行,發現可以了。 測試把D盤中的軟件以管理員權限運行,生成的也是可以的,所以在安裝的時候報  無法修改 con.ini文件到C盤 這個錯是不是有什麼影響,並且以管理員權限運行的時候也沒有修復  ?

(搜索材料的時候依賴了很多前輩的經驗,感謝!)

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章