2016-07-27 197 views
2

我有一個安裝腳本,允許用戶指定他們想要安裝我的應用程序的位置。它是在[Code]塊內的Pascal腳本的形式。Inno安裝從文件(.inf)爲靜默安裝加載默認的自定義安裝設置

var 
    SelectUsersPage: TInputOptionWizardPage; 
    IsUpgrade : Boolean; 
    UpgradePage: TOutputMsgWizardPage; 

procedure InitializeWizard(); 
var 
    AlreadyInstalledPath: String; 
begin 
    { Determine if it is an upgrade... } 
    { Read from registry to know if this is a fresh install or an upgrade } 
    if RegQueryStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppId}_is1', 'Inno Setup: App Path', AlreadyInstalledPath) then 
    begin 
     { So, this is an upgrade set target directory as installed before } 
     WizardForm.DirEdit.Text := AlreadyInstalledPath; 
     { and skip SelectUsersPage } 
     IsUpgrade := True; 

     { Create a page to be viewed instead of Ready To Install } 
     UpgradePage := CreateOutputMsgPage(wpReady, 
     'Ready To Upgrade', 'Setup is now ready to upgrade {#MyAppName} on your computer.', 
     'Click Upgrade to continue, or click Back if you want to review or change any settings.'); 
    end 
    else 
    begin 
     IsUpgrade:= False; 
    end; 

    { Create a page to select between "Just Me" or "All Users" } 
    SelectUsersPage := CreateInputOptionPage(wpLicense, 
    'Select Users', 'For which users do you want to install the application?', 
    'Select whether you want to install the library for yourself or for all users of this computer. Click next to continue.', 
    True, False); 

    { Add items } 
    SelectUsersPage.Add('All users'); 
    SelectUsersPage.Add('Just me'); 

    { Set initial values (optional) } 
    SelectUsersPage.Values[0] := False; 
    SelectUsersPage.Values[1] := True; 
end; 

所以問題是我怎麼能支持靜默安裝?當用戶調用/SILENT/VERYSILENT時,安裝程​​序默認爲SelectUsersPage.Values[1],該值爲Just Me。我想幫助支持希望通過提供答案文件來更改安裝目錄的用戶。

我沒有開發所有這些代碼,並且我是一個Pascal的新手。

謝謝。

+0

它默認爲你問它默認什麼。所以改變默認值。 –

+0

你爲什麼低調呢?我不問在嚮導期間如何更改默認值。我問如何處理用戶可以提供的靜默安裝參數文件,以便他們控制他們希望安裝應用程序的位置。 –

+0

嗯,正是爲了這個。讓你向我們解釋你想要什麼。問題是缺少這一確切的信息。現在+1。 –

回答

1

您可以將自定義密鑰(例如Users)添加到由/SAVEINF創建的.inf文件中。

然後在安裝程序中,查找在/LOADINF command-line argument和讀取密鑰並採取相應的行動:

procedure InitializeWizard(); 
var 
    InfFile: string; 
    I: Integer; 
    UsersDefault: Integer; 
begin 
    ... 

    InfFile := ExpandConstant('{param:LOADINF}'); 

    UsersDefault := 0; 

    if InfFile <> '' then 
    begin 
    Log(Format('Reading INF file %s', [InfFile])); 
    UsersDefault := 
     GetIniInt('Setup', 'Users', UsersDefault, 0, 0, ExpandFileName(InfFile)); 
    Log(Format('Read default "Users" selection %d', [UsersDefault])); 
    end 
    else 
    begin 
    Log('No INF file'); 
    end; 

    SelectUsersPage.Values[UsersDefault] := True; 
end; 
+0

謝謝!我沒有首先得知INF文件中需要存儲密鑰及其值的位置,直到查找GetiniInt()函數,並且看到我需要在[Setup]部分創建一個Users鍵。我不得不添加一些額外的代碼來查看「IsUpgrade」是否設置爲True,因此您提供的代碼塊在升級過程中不會執行。非常感謝您的幫助! –