如何在Inno Setup中为每个用户(包括将来的新用户)安装文件? [英] How to install files for each user, including future new users, in Inno Setup?

查看:249
本文介绍了如何在Inno Setup中为每个用户(包括将来的新用户)安装文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装程序,需要分发一些默认文件供用户修改.每个Windows用户配置文件都需要拥有自己的这些(可写)文件副本,包括将来在Windows中创建新用户的时间.

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.

我已经知道如何分发到当前用户的个人资料,但是不了解所有用户个人资料,尤其是将来的用户.我已经了解了某些软件如何自动将文件包含在新的Windows用户个人资料中.

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.

如何使Inno Setup以这种方式分发文件?

How can I make Inno Setup distribute files in such a manner?

推荐答案

对于所有现有帐户,参见:
Inno设置在所有用户的所有桌面上创建单独的快捷方式

对于将来的帐户: Default User配置文件中的所有内容都会自动复制到所有新创建的配置文件中.

For future accounts: Whatever is in the Default User profile gets automatically copied to all newly created profiles.

因此,如果要将文件添加到所有新用户的文档"文件夹中,请将其添加到Default User配置文件的Documents文件夹中.通常是什么:

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

要检索正确的路径,请使用 SHGetFolderPath ,其中nFolder参数设置为您要使用的路径(例如,CSIDL_PERSONAL表示"documents"文件夹),而hToken参数设置为-1(默认用户配置文件).

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;

(代码用于 Unicode版本的Inno Setup ).

这篇关于如何在Inno Setup中为每个用户(包括将来的新用户)安装文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆