首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从注册表中获取Inno安装程序的Office安装目录

如何从注册表中获取Inno安装程序的Office安装目录
EN

Stack Overflow用户
提问于 2015-01-12 03:44:19
回答 2查看 3K关注 0票数 2

我正在为Microsoft创建一个安装程序,特别是2007-2013版本。它只是在两个Office目录中复制一些文件。我的Windows是64位,但是我想为x64和x86架构创建一个安装程序。

因此,我编写了以下代码,试图从Windows注册表获取Office的安装路径。而且,对于Office的每个版本(2007-2013年),它采用安装的路径,并附加我需要的路径的其余部分。这就是我想要的结果。

代码语言:javascript
复制
[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;

使用其中一个路径,我尝试在Inno安装程序中设置文件的安装路径(DestDir),如下所示:

代码语言:javascript
复制
[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位节点问题,但没有去。

有人能帮我吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-12 18:05:31

在64位系统上运行32位安装程序时,Inno将自动将HKLM展开为HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node,这意味着您不必在这里操作,除非安装了64位office,可以在64位注册表分支中保存他的注册表信息。但是,您可以对HKLM64进行额外的检查,如果是IsWin64 = true。虽然您必须将它作为String传递,但是而不是 Integer,就像在代码中那样。

我会这样称呼它(但我不太理解您的代码的最后一部分,因此我刚刚粘贴了它):

代码语言:javascript
复制
[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
EN

Stack Overflow用户

发布于 2015-03-08 05:18:38

在你的帮助下,这是我解决问题的最后办法。我注意到,我错过了第64行(DestDir参数)中最后的双引号。

代码语言:javascript
复制
; 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;

谢谢大家,各位!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27895014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档