2015-01-12 3 views
1

Microsoft Office 용 설치 프로그램, 특히 2007 - 2013 버전을 만듭니다. 두 개의 Office 디렉토리에있는 일부 파일을 복사하기 만하면됩니다. 내 Windows는 64 비트이지만 x64 및 x86 아키텍처 용 설치 프로그램을 만들고 싶습니다.Office의 설치 디렉토리를 Inno Setup 설치 프로그램의 레지스트리에서 가져 오는 방법

그래서 Windows 레지스트리에서 Office 설치 경로를 가져 오는 다음 코드를 작성했습니다. 그리고 각 버전의 Office (2007 - 2013)에서는 설치 경로가 필요하고 나머지 경로가 추가됩니다. 그게 내가 원하는 결과 야.

[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 : 경로 중 하나와

[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)를 설정하려 각 줄에 올바른 경로를 설정하는 데 도움이됩니다. 그러나 RegKeyExists 또는 RegQueryStringValue 레지스트리의 하위 키를 찾을 수 없습니다. 나는 64 비트 노드 문제 때문에 아무 것도하지 않기 때문에 GetHKLM() 함수를 사용해 보았다.

아무도 도와 줄 수 있습니까?

답변

0

64 비트 시스템에서 32 비트 설정을 실행하는 경우 Inno는 자동으로 HKLMHKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node으로 확장합니다. 64 비트 레지스트리가 64 비트 레지스트리 분기에있을 수있는 64 비트 Office가 설치되어 있지 않으면 여기서 조작 할 필요가 없습니다. 그렇다면 에 대한 추가 검사를 수행 할 수 있습니다 (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;으로 정의합니다. 따라서 루트 키는 정수 여야합니다. –

+0

RegKeyExists (GetHKLM(), 'SOFTWARE \ Microsoft \ Office \ 15.0 \ Common \ InstallRoot')를 사용하면 언제 레지스트리 편집을 처음 사용하는 지 이해할 수 없습니다. 왜 if는 'SOFTWARE \ 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; 

여러분 모두에게 감사드립니다!