2017-10-29 14 views
1

Inno Setup ExcelAddinInstaller을 사용하고 있습니다.Inno Setup을 사용하여 신뢰할 수있는 위치에 Excel Addin 폴더 추가

{ 
    Looks up the localized Addins folder in the registry. 
    This function is used in the [Files] section of the 
    script, where function calls always expect a parametrized 
    function. This function does not require a parameter. 
    Therefore, a dummy parameter is defined. 
} 
function GetDestDir(dummyparameter: string): string; 
var 
    Addins: string; 
    s: string; 
    CallName: string; 
    i: integer; 
begin 
    if DestDir = '' then 
    begin 
    CallName := 'GetDestDir(' + dummyparameter + '): '; 
    log(CallName+'Trying to find addins folder name'); 

    { 
     Note the trailing backslash 
    } 
    DestDir := ExpandConstant('{userappdata}\Microsoft\'); 

    { 
     Loop through possible version numbers of Excel and find out if 
     any installed version uses an addin folder other than "addins". 
     This can be the case with international versions (other than English). 
     If an addin folder name that is different from "Addins" is found, 
     the addin will be installed into a dedicated folder. 
    } 
    for i := 8 to 32 do 
    begin 
     s := ''; 
     if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\Office\' 
     +IntToStr(i)+'.0\Common\General', 'AddIns', s) then 
     begin 
     if Length(Addins) > 0 then 
     begin 
      { 
      If the Addins variable has been set already and we encounter 
      a different name, reset everything in order to use a dedicated 
      name further on. 
      } 
      if s <> Addins then 
      begin 
      { 
       Set the Addins variable to a zero-length string to force 
       using a dedicated dir name later. 
      } 
      log(CallName+'Found alternative Addins key for version '+IntToStr(i)+': "'+s+'"'); 
      Addins := ''; 
      { 
       Once a single dir name that is different from "Addins" was 
       found, we can exit the loop. 
      } 
      break; 
      end 
     end 
     else 
     begin 
      { 
      Addins variable has zero length: Set it to the current value of s 
      } 
      log(CallName+'Found first Addins key: version '+IntToStr(i)+', "'+s+'"'); 
      Addins := s; 
     end 
     end 
    end; 

    { 
     Check if the Addins variable contains something now; if not, use 
     a default value ('XL Toolbox') 
    } 
    if Addins = '' then 
    begin 
     DestDir := ExpandConstant('{userappdata}\Microsoft\Addins\'); 
     RegisterWithFullPath := true; 
     log(CallName+'Using dedicated folder: "'+DestDir+'"'); 
    end 
    else 
    begin 
     DestDir := ExpandConstant('{userappdata}\Microsoft\' + Addins); 
     RegisterWithFullPath := false; 
     log(CallName+'Installing to default Addins folder: ' + DestDir); 
    end; 
    end; 
    result := DestDir; 
end; 

그러나 Excel에서 2016 년과 2013 년 추가 기능이 기본적으로 설치되어있는 폴더를 추가 설치하고, 엑셀하여 "신뢰할 수있는 위치"로 정의하지 않고, 될하지 않는 것이 발생 Excel에 표시됩니다. 나는 GetDestDir에 의해 반환 된 경로를 추가 찾고 있어요

Trusted Locations에서

HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Excel\Secur‌​‌​ity\Trusted Locations\MyLocation 

답변

1

다음 코드는 사용되지 않은 첫 번째 LocationX 하위 키를 찾아 추가하고 거기에 Addins 경로 기록 될 :

const 
    TrustedLocationsKey = 
    'Software\Microsoft\Office\16.0\Excel\Security\Trusted Locations'; 

procedure AddAddinsToExcelTrustedLocations; 
var 
    LocationIndex: Integer; 
    LocationKey: string; 
    Path: string; 
begin 
    if not RegKeyExists(HKEY_CURRENT_USER, TrustedLocationsKey) then 
    begin 
    MsgBox('Excel trusted locations registry key not found', mbError, MB_OK); 
    end 
    else 
    begin 
    { Find unused LocationX } 
    LocationIndex := 0; 
    repeat 
     LocationKey := Format('%s\Location%d', [TrustedLocationsKey, LocationIndex]); 
     Log(Format('Trying %s', [LocationKey])); 
     Inc(LocationIndex); 
    until (not RegKeyExists(HKEY_CURRENT_USER, LocationKey)); 

    Log(Format('Will use %s', [LocationKey])); 

    { Addins is the variable from your question code } 
    Path := GetDestDir(''); 
    if not RegWriteStringValue(HKEY_CURRENT_USER, LocationKey, 'Path', Path) then 
    begin 
     MsgBox(
     Format('Cannot add %s to Excel trusted locations', [Path]), mbError, MB_OK); 
    end 
     else 
    begin 
     Log(Format('Added %s to Excel trusted locations', [Path])); 
    end; 
    end; 
end; 

procedure CurStepChanged(CurStep: TSetupStep); 
begin 
    if CurStep = ssPostInstall then 
    begin 
    AddAddinsToExcelTrustedLocations; 
    end; 
end; 
+0

을 추가 기능은 실제로 "템플릿"에 올바르게 설치되지만 Excel에서는 등록되지 않습니다. 작업을 수행해야하는 파스칼 함수를 도울 수 있습니까? – user3387046

+0

귀하의 질문에 등록 코드가 표시되어 있지 않습니다. 템플릿에 AddIn을 설치하는 것이 올바른 방법이라고 확신합니까? –

+0

나는 그것이 최선의 접근법이라고 확신하지는 않지만 "신뢰할 수있는 위치"에 설치해야합니다. 그렇지 않으면 Excel 탭에 표시되지 않습니다. 코드는 [여기]가 나타납니다 (http://metrics-institute.com/avibenita/InnoRegister.txt) – user3387046