AppData \ LocalLow的常量?

时间:2016-02-05 08:57:57

标签: inno-setup

目前要访问LocalLow我使用:

{%USERPROFILE}\AppData\LocalLow

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

2 个答案:

答案 0 :(得分:2)

AppData\LocalLow没有常数。

您可以使用Pascal Scripting来解决它。

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

由于Unicode Inno Setup中缺少(宽)PChar类型,实现涉及很少的黑客攻击。

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;

答案 1 :(得分:0)

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

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