2015-01-12 2 views
1

Я создаю установщик для Microsoft Office, в частности для версий 2007 - 2013 годов. Он просто копирует некоторые файлы внутри двух каталогов Office. Моя Windows 64-разрядная, но я хочу создать установщик для x64 и x86-архитектур.Как установить каталог установки Office из реестра установщика Inno Setup

Итак, я написал следующий код, который пытается извлечь из реестра Windows путь установки Office. И, для каждой версии Office (2007 - 2013), она берет путь установки и добавляет остальную часть пути, в котором я нуждаюсь. Это результат, который я хочу.

[Code] 
function GetHKLM() : Integer; 

begin 
if IsWin64 then 
    begin 
    Result := HKLM64; 
    end 
    else 
    begin 
    Result := HKEY_LOCAL_MACHINE; 
    end; 
end; 

function officeInstallDir(Param: string): string; 
// This function takes the type of desired directory, 
// verify the version of Office and returns the correct 
// directory for style or bibform. 

var 
    styleFolder, bibformFolder : string; 

begin 
    // It verifies the Office version through the registry's subkey and it sets the correct Office's path. 
    if RegKeyExists(GetHKLM(), '\SOFTWARE\Microsoft\Office\15.0') then begin 
     styleFolder  := '{userappdata}\Roaming\Microsoft\Bibliography\Style'; 
     RegQueryStringValue(GetHKLM(), '\SOFTWARE\Microsoft\Office\15.0\Common', 'InstallRoot', bibformFolder); 
     bibformFolder := bibformFolder + '\1046\Bibliography'; 
    end else begin 
     if RegKeyExists(GetHKLM(), '\SOFTWARE\Microsoft\Office\14.0') then begin 
      RegQueryStringValue(GetHKLM(), '\SOFTWARE\Microsoft\Office\14.0\Common', 'InstallRoot', styleFolder); 
      styleFolder  := styleFolder + 'Bibliography\Style'; 
      bibformFolder := styleFolder + '1046\Bibliography'; 
     end else begin 
      if RegKeyExists(GetHKLM(), '\SOFTWARE\Microsoft\Office\12.0') then begin 
      RegQueryStringValue(GetHKLM(), '\SOFTWARE\Microsoft\Office\12.0\Common', 'InstallRoot', styleFolder); 
      styleFolder  := styleFolder + 'Bibliography\Style'; 
      bibformFolder := styleFolder + '1046\Bibliography'; 
      end 
     end; 
    end; 

    // Set the result according Param passed (the first or second type of path). 
    if Param = 'style' then begin 
     result := styleFolder; 
    end else begin 
     result := bibformFolder; 
    end; 

end; 

С одним из путей, я попытался установить инсталляционный путь к файлу (DestDir) в Inno Setup, как это:

[Files] 
Source: "E:\Google Drive\Informática\Bibword\Bibword Estilos\*"; DestDir: "{code:officeInstallDir|style}"; Flags: ignoreversion 
Source: "E:\Google Drive\Informática\Bibword\Bibword file\BIBFORM.xml"; DestDir: "{code:officeInstallDir|bibform}"; Flags: ignoreversion 

Но если я прохожу стиль параметров или bibform, функция officeInstallDir должен помочь мне установить правильный путь для каждой строки. Но RegKeyExists или RegQueryStringValue не находит подразделы реестра. Я даже попытался использовать функцию GetHKLM(), потому что проблема с 64-битным узлом, но не ушла.

Может кто-нибудь мне помочь?

ответ

0

При запуске 32-битной настройки на 64-битной системе Inno автоматически расширяет HKLM как HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node, что означает, что вам не нужно манипулировать здесь, если не установлено 64-разрядное офисное устройство, которое может хранить его информацию о реестре в 64-разрядной ветви реестра. Но тогда вы можете сделать дополнительную проверку для HKLM64, если IsWin64 = true. Хотя вы должны передать его как String, но неInteger как вы это делаете в своем коде.

Я бы назвал это так (но я не совсем понимаю, заключительную часть вашего кода, таким образом, я просто вставили его):

[Code] 
function officeInstallDir(Param: string): string; 
var 
    styleFolder, bibformFolder : string; 

begin 
    if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot') then 
    begin 
     RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot', 'Path', bibformFolder); 
     styleFolder := ExpandConstant('{userappdata}') + '\Roaming\Microsoft\Bibliography\Style'; 
     bibformFolder := bibformFolder + '\1046\Bibliography'; 
    end 
    else begin 
     if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot') then 
     begin 
      RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot', 'Path', styleFolder); 
      styleFolder := styleFolder + 'Bibliography\Style'; 
      bibformFolder := styleFolder + '1046\Bibliography'; 
     end 
     else begin 
      if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\12.0\Common\InstallRoot') then 
      begin 
      RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Office\12.0\Common\InstallRoot', 'Path', styleFolder); 
      styleFolder := styleFolder + 'Bibliography\Style'; 
      bibformFolder := styleFolder + '1046\Bibliography'; 
      end; 
     end; 
    end; 


    // I quite don't get this part here: 
    if Param = 'style' then 
    begin 
     result := styleFolder; 
    end 
    else begin 
     result := bibformFolder; 
    end; 

end; 
+0

Спасибо за ответ, но я попробовал ваше предложение о GetHKLM() и возникла ошибка в функции RegKeyExists(). Справка определяет эту функцию как функцию RegKeyExists (const RootKey: Integer; const SubKeyName: String): Boolean ;. Таким образом, Rootkey должен быть целым числом. –

+0

Поскольку я новичок в программировании реестра, я совершенно не понимаю, когда я использую ваши «if RegKeyExists» (GetHKLM(), «SOFTWARE \ Microsoft \ Office \ 15.0 \ Common \ InstallRoot»), тогда «и это сработало? Почему if не работал с «ПРОГРАММНОЕ ОБЕСПЕЧЕНИЕ \ Microsoft \ Office \ 15.0»? И еще раз спасибо! –

+0

И еще одна вещь. Я должен изменить строку с помощью 'styleFolder: = '{userappdata} \ Roaming \ Microsoft \ Bibliography \ Style';' для 'styleFolder: = ExpandConstant ('{userappdata} \ Microsoft \ Bibliography \ Style');'. –

0

С вашей помощью, это мое окончательное решение проблема. Я отметил, что пропустил последнюю двойную кавычку в строке 64 (параметр DestDir).

; Script generated by the Inno Setup Script Wizard. 
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! 

#define MyAppName "Bibword para Office em português" 
#define MyAppVersion "1.0" 
#define MyAppPublisher "Yves e Lehnemann" 
#define MyAppURL "https://bibword.codeplex.com/" 
#define MyAppExeName "BibWordExtender2.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={{757B986A-1757-4DEC-9B7B-B2027ADD1147} 
AppName={#MyAppName} 
AppVersion={#MyAppVersion} 
;AppVerName={#MyAppName} {#MyAppVersion} 
AppPublisher={#MyAppPublisher} 
AppPublisherURL={#MyAppURL} 
AppSupportURL={#MyAppURL} 
AppUpdatesURL={#MyAppURL} 
DefaultDirName={pf}\{#MyAppName} 
DefaultGroupName={#MyAppName} 
OutputDir=r:\Software 
OutputBaseFilename=Bibword para Office em português 
SetupIconFile=R:\Software\applications_office.ico 
Compression=lzma 
SolidCompression=yes 

[Languages] 
Name: "english"; MessagesFile: "compiler:Default.isl" 
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" 
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl" 
Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.isl" 
Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl" 
Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl" 
Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.isl" 
Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl" 
Name: "french"; MessagesFile: "compiler:Languages\French.isl" 
Name: "german"; MessagesFile: "compiler:Languages\German.isl" 
Name: "greek"; MessagesFile: "compiler:Languages\Greek.isl" 
Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl" 
Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl" 
Name: "italian"; MessagesFile: "compiler:Languages\Italian.isl" 
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl" 
Name: "nepali"; MessagesFile: "compiler:Languages\Nepali.islu" 
Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl" 
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl" 
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl" 
Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl" 
Name: "scottishgaelic"; MessagesFile: "compiler:Languages\ScottishGaelic.isl" 
Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl" 
Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl" 
Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl" 
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl" 
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl" 
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl" 

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

[Files] 
Source: "R:\Software\BibWordExtender2.exe"; DestDir: "{app}"; Flags: ignoreversion 
Source: "R:\Software\Bibword Estilos\*"; DestDir: "{code:officeInstallDir|style}"; Flags: ignoreversion 
Source: "R:\Software\Bibword file\BIBFORM.xml"; DestDir: "{code:officeInstallDir|bibform}"; Flags: ignoreversion 
; NOTE: Don't use "Flags: ignoreversion" on any shared system files 

[Icons] 
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" 
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" 
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon 

[Code] 
// This function verifies the system's architecture (x32 ou x64). 
// It returns the registry's root key according to the system architecture. 
function GetHKLM() : Integer; 

begin 
if IsWin64 then 
    begin 
    Result := HKLM64; 
    end 
    else 
    begin 
    Result := HKEY_LOCAL_MACHINE; 
    end; 
end; 


// This function takes the type of desired directory (the directory for installation of styles or 
// the general form of Bibliographic Sources), verify the version of Office with 
// the installation directory (RegQueryStringValue() function that saves the directory 
// bibformFolder or styleFolder and returns 1 if there is a key, which is the second parameter) 
// and returns the correct directory for styles or bibform file. 
// It has a parameter that need the Param name (see help for {code: |}) and be 
// of type string. 
function officeInstallDir(Param: string): string; 


var 
    // rootKey receives the result of GetHKLM() function, that is, the root key according to 
    // the system architecture. 
    // styleFolder, bibformFolder keep the addresses (folder's path) for the installation 
    // of styles and form of Bibliographic Sources (bibform.xml). 
    rootKey : Integer; 
    styleFolder, bibformFolder : String; 

begin 
    // rootKey receives the value of function below according to 
    // the system architecture. 
    rootKey := GetHKLM(); 

    // Checks the version of Office (looking for the existence of the value of 'Path' in 
    // Windows registry) and configures the necessary directories. 

    // I had problems with this function because it did not recognize the subkey 
    // '\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot', since the correct form is written below. 

    // It did not work the use of function RegKeyExists(ROOTKEY, "SOFTWARE\Microsoft\Office\15.0'), for example, 
    // because other Offices could already have been installed before, which kept the subkey in the system. 

    // I had to use the ExpandConstant() function because the address does not translate the constant {userappdata} 
    // (and it already comes with the Roaming directory). 

    // And in the last two ifs, I had to change the order of the position of the styleFolder's and bibformFolder's variables 
    // because I need the pure installation directory to generate the bibformFolder's directory, and only after 
    // I can upgrade it to generate the styleFolder's. 
    if RegQueryStringValue(rootKey, 'SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot', 'Path', bibformFolder) then begin 
     styleFolder  := ExpandConstant('{userappdata}\Microsoft\Bibliography\Style'); 
     bibformFolder := bibformFolder + '1046\Bibliography'; 
    end else begin 
     if RegQueryStringValue(rootKey, 'SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot', 'Path', styleFolder) then begin 
      bibformFolder := styleFolder + '1046\Bibliography'; 
      styleFolder  := styleFolder + 'Bibliography\Style';   
     end else begin 
      if RegQueryStringValue(rootKey, 'SOFTWARE\Microsoft\Office\12.0\Common\InstallRoot', 'Path', styleFolder) then begin 
      bibformFolder := styleFolder + '1046\Bibliography'; 
      styleFolder  := styleFolder + 'Bibliography\Style'; 

      end 
     end; 
    end; 

    // Adjusts the result according to the type of desired directory. 
    if Param = 'style' then begin 
     result := styleFolder; 
    end else begin 
     result := bibformFolder; 
    end; 

end; 

Спасибо всем, ребята!

Смежные вопросы