我有一个安装程序需要分发一些默认文件供用户修改。每个Windows用户配置文件都需要拥有自己的这些(可写)文件的副本,包括将来在Windows中创建新用户的时间。
我已经知道如何分发到当前用户的个人资料,但不知道所有用户个人资料,尤其是未来的用户。我已经看到一些软件如何在新的Windows用户配置文件中自动包含文件。
如何让Inno Setup以这种方式分发文件?
答案 0 :(得分:1)
对于所有现有帐户,请参阅:
Inno Setup Create individual shortcuts on all desktops of all users
对于将来的帐户: Default User
个人资料中的任何内容都会自动复制到所有新创建的个人资料中。
因此,如果要将文件添加到所有新用户的“文档”文件夹,请将其添加到Documents
个人资料的Default User
文件夹中。通常是:
C:\Users\Default\Documents
要检索正确的路径,请使用SHGetFolderPath
并将nFolder
参数设置为您之后的路径(例如CSIDL_PERSONAL
表示“documents”文件夹)和hToken
参数设置为-1
(默认用户个人资料)。
[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;
(代码适用于Unicode version of Inno Setup)。