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).