2016-02-05 240 views
0

目前访问LocalLow我用这个:AppData LocalLow常量?

{%USERPROFILE}\AppData\LocalLow 

但我想知道是否有用于在INNO一组常数,因为这两个RoamingLocal有一个。

+0

不幸的是没有,因为在Windows中LocalLow没有环境变量。虽然你可能想看看[那个主题](http://stackoverflow.com/questions/4494290/detect-the-location-of-appdata-locallow)。编辑:您可能想要连接Evnironmental变量与字符串解决方案。 'S:= ExpandConstant('{%LocalAppData}'+'Low');' – RobeN

+0

是的,很多解决方法,但没有实际的常数。另一方面,如果没有环境变量,程序如何使用? –

+0

程序使用'SHGetKnownFolderPath'。 Inno安装程序不使用环境变量来解析常量。它主要使用(不建议使用)'SHGetFolderPath'。它只为'userpf'和'usercf'使用'SHGetKnownFolderPath',因为'SHGetFolderPath'(它不支持'LocalLow')不支持。 –

回答

1

AppData\LocalLow没有常数。

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

要解决“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 '[email protected] stdcall'; 

{ And allow the Integer to be copied to string } 
function StrCpy(Dest: string; Source: Integer): Integer; 
    external '[email protected] stdcall'; 

{ And allow the Integer pointer to be released } 
procedure CoTaskMemFreeAsInteger(pv: Integer); 
    external '[email protected] 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 } 
    for I := 1 to MAX_PATH do 
    begin 
     if Result[I] = #0 then 
     begin 
     SetLength(Result, I - 1); 
     Break; 
     end; 
    end; 
    end; 
end; 

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

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

而且你需要更改功能签名采取虚拟参数:

function GetAppDataLocalLow(Param: string): string; 
0

例如,删除文件时卸载m LocalLow with INNO:

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