【问题标题】:Constant for AppData\LocalLow in Inno Setup?Inno 设置中 AppData\LocalLow 的常量?
【发布时间】:2016-02-05 08:57:57
【问题描述】:

目前访问LocalLow我用这个:

{%USERPROFILE}\AppData\LocalLow

但我想知道 Inno Setup 中是否有一个常数,因为 RoamingLocal 都有一个。

【问题讨论】:

    标签: windows installation inno-setup environment


    【解决方案1】:

    AppData\LocalLow 没有常数。

    您可以使用 Pascal 脚本来解决它。

    要解决“LocalLow”,必须使用SHGetKnownFolderPath
    另见Detect the location of AppData\LocalLow

    由于在 Unicode Inno 设置中缺少(宽)PChar 类型,该实现涉及很少的 hack。

    const
      MAX_PATH = 260;
      AppDataLocalLowGUID = '{A520A1A4-1780-4FF6-BD18-167343C5AF16}';
    
    { There's no PChar in Unicode Inno Setup, }
    { pretend the function returns a pointer to an Integer }
    function SHGetKnownFolderPath(rfid: TGUID; dwFlags: DWORD; hToken: THandle;
      var ppszPath: Integer): Integer;
      external 'SHGetKnownFolderPath@Shell32.dll stdcall';
    
    { And allow the Integer to be copied to string }
    function StrCpy(Dest: string; Source: Integer): Integer;
      external 'StrCpyW@Shlwapi.dll stdcall';
    
    { And allow the Integer pointer to be released }
    procedure CoTaskMemFreeAsInteger(pv: Integer);
      external 'CoTaskMemFree@Ole32.dll stdcall';
    
    function GetAppDataLocalLow: string;
    var
      Path: Integer;
      I: Integer;
    begin
      if SHGetKnownFolderPath(StringToGUID(AppDataLocalLowGUID), 0, 0, Path) = 0 then
      begin
        { The path should not be longer than MAX_PATH }
        SetLength(Result, MAX_PATH);
    
        StrCpy(Result, Path);
    
        CoTaskMemFreeAsInteger(Path);
    
        { Look for NUL character and adjust the length accordingly }
        SetLength(Result, Pos(#0, Result) - 1);
      end;
    end;
    

    如果您需要在非Code 部分(Pascal 脚本之外)使用路径,可以使用scripted constant

    [Files]
    Source: myfile.txt; DestDir: {code:GetAppDataLocalLow}
    

    您需要更改函数签名以采用虚拟参数:

    function GetAppDataLocalLow(Param: string): string;
    

    【讨论】:

      【解决方案2】:

      例如,使用 INNO 从 LocalLow 卸载时删除文件:

      [UninstallDelete]
      Type: filesandordirs; Name: "{userappdata}\..\LocalLow\MyFile.txt"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多