Installing file in users AppData folder using inno

2019-01-23 18:24发布

问题:

I am using Inno-Setup version 5.5.3(a).

[Files]
Source: "C:\GPT\GPT.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\GPT\GPT.dat"; DestDir: "{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

I would like to install the "GPT.dat" file into the users AppData folder in a custom folder called "GPT"

e.g. AppData\GPT\

for example, in my delphi code, I create a folder called "GPT" in the users AppData path. These is where I would like to place the file

var
  path: array[0..MAX_PATH] of char;

 SHGetFolderPath(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, @path);
 userPath:= Path;
 UserPath:= UserPath + '\GPT\';
 if not DirectoryExists(UserPath) then
   CreateDir(UserPath);

Can anyone tell me how to edit my [Files] section of my Inno script to make this happen?

Thanks

回答1:

You need to use the {userappdata} constant, which is mapped just to the CSIDL_APPDATA item ID, as a destination directory for your files:

[Files]
Source: "C:\GPT\GPT.dat"; DestDir: "{userappdata}\GPT\"; Flags: ignoreversion createallsubdirs recursesubdirs comparetimestamp

{userappdata} & {commonappdata} The path to the Application Data folder.

 CSIDL_APPDATA = {userappdata} = C:\Documents and Settings\username\Application Data
 CSIDL_COMMON_APPDATA = {commonappdata} = C:\Documents and Settings\All Users\Application Data


回答2:

It seems more appropriate to use {programdata}, if I interpret Mirals comment correctly.

However, on XP there is no {programdata}, only {commonappdata} or {userappdata}, so I have to diversify my install. {programdata} is a later invention.

A disturbing trap is when the desktop and userappdata are mirrored to the server ("roaming profile"), that slows programs down greatly if they use userappdata for ini file storage, at least that's my experience.



回答3:

You need to use : {userappdata}
If you check the Inno Setup documentation :

{userappdata} = C:\Documents and Settings\username\AppData\Roaming\
{commonappdata} = C:\Documents and Settings\All Users\AppData\Roaming\

{localappdata} : The path to the local (nonroaming) Application Data folder.
{userappdata} & {commonappdata} : The path to the Application Data folder.

I use :

[Files]
Source: MyPath\* ;  Flags: recursesubdirs createallsubdirs; DestDir: {userappdata}\MySoftware\ ; Components: ConfigFiles

And my config files are in :

C:\Users*\AppData\Roaming\MySoftware**



标签: inno-setup