问题
I have an installer which needs to distribute some default files for the user to modify. Each Windows user profile needs to have its own copy of these (writable) files, including when a new user is created in Windows in the future.
I already know how to distribute to the current user's profile, but have no idea about all user profiles, especially future users. I've seen how some software can automatically include files in a new Windows user's profile.
How can I make Inno Setup distribute files in such a manner?
回答1:
For all existing accounts, see:
Inno Setup Create individual shortcuts on all desktops of all users
For future accounts: Whatever is in the Default User
profile gets automatically copied to all newly created profiles.
So if you want to add a file to all new users' "documents" folder, add it to the Documents
folder of the Default User
profile. What typically is:
C:\Users\Default\Documents
To retrieve the correct path, use SHGetFolderPath with nFolder
argument set to the path you are after (e.g. CSIDL_PERSONAL
for "documents" folder) and the hToken
argument set to -1
(default user profile).
[Files]
Source: "default.txt"; DestDir: "{code:GetDefaultUserDocumentsPath}"
[Code]
const
CSIDL_PERSONAL = $0005;
SHGFP_TYPE_CURRENT = 0;
MAX_PATH = 260;
S_OK = 0;
function SHGetFolderPath(
hwnd: HWND; csidl: Integer; hToken: THandle; dwFlags: DWORD;
pszPath: string): HResult;
external 'SHGetFolderPathW@shell32.dll stdcall';
function GetDefaultUserDocumentsPath(Param: string): string;
var
I: Integer;
begin
SetLength(Result, MAX_PATH);
if SHGetFolderPath(0, CSIDL_PERSONAL, -1, SHGFP_TYPE_CURRENT, Result) <> S_OK then
begin
Log('Failed to resolve path to default user profile documents folder');
end
else
begin
{ Look for NUL character and adjust the length accordingly }
SetLength(Result, Pos(#0, Result) - 1);
Log(Format('Resolved path to default user profile documents folder: %s', [Result]));
end;
end;
(The code is for Unicode version of Inno Setup).
来源:https://stackoverflow.com/questions/44477941/how-to-install-files-for-each-user-including-future-new-users-in-inno-setup