首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Inno安装程序在所有用户的所有桌面上创建单独的快捷方式

Inno安装程序在所有用户的所有桌面上创建单独的快捷方式
EN

Stack Overflow用户
提问于 2016-02-05 12:53:13
回答 1查看 4.7K关注 0票数 6

我正在使用Inno安装程序在用户桌面上创建一个快捷方式:

代码语言:javascript
运行
复制
Name: "{commondesktop}\Setup"; Filename: "{app}\Setup.exe"; WorkingDir: "{pf}\Program"; IconFilename: "{app}\Setup.ico"

但是用户,没有管理权限,不能删除这个快捷方式,如何授予普通用户权限,以删除这个图标?图标应该在每个用户的桌面上创建,但是用户应该拥有删除它的权限。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-05 13:41:39

{commondesktop}快捷方式在普通桌面上共享。所以只有一份抄近路。

如果允许用户删除,则当一个用户删除该图标时,该图标将被删除。这就是为什么不允许常规用户修改/删除共享快捷方式。

虽然可以向所有用户授予该快捷方式的删除权限,但您不应该这样做。

如果每台机器只由一个用户使用,请将图标安装到userdesktop,而不是commondestop。但是,只有当用户(而不是管理员)实际运行安装程序时,这才有效。有关此问题的一般性讨论,请参阅Installing application for currently logged in user from Inno Setup installer running as Administrator

要将图标安装到所有桌面上,没有一种简单的方法。您必须使用Pascal脚本并迭代所有配置文件。

简单的方法是迭代C:\Users的子文件夹,在每个用户的子文件夹的Desktop子文件夹中创建一个快捷方式:

代码语言:javascript
运行
复制
procedure CurStepChanged(CurStep: TSetupStep);
var
  UsersPath: string;
  CommonDesktopShortPath: string;
  DesktopPath: string;
  ShortcutPath: string;
  FindRec: TFindRec;
  ShortcutsCount: Integer;
begin
  { Once the files are installed }
  if CurStep = ssPostInstall then
  begin
    Log('Creating shortcuts');
    { Assuming the common users root (typically C:\Users) is two level up }
    { from the current user desktop folder }
    UsersPath :=
      AddBackslash(ExtractFilePath(RemoveBackslash(ExtractFilePath(
        RemoveBackslash(ExpandConstant('{userdesktop}'))))));
    Log(Format('Users root [%s]', [UsersPath]));
    CommonDesktopShortPath := GetShortName(ExpandConstant('{commondesktop}'));
    Log(Format('Common desktop [%s]', [CommonDesktopShortPath]));

    ShortcutsCount := 0;

    { Iterate all users }
    if FindFirst(UsersPath + '*', FindRec) then
    begin
      try
        repeat
          { Just directories, not interested in files }
          if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
          begin
            { Check if there is a Desktop subfolder }
            DesktopPath := UsersPath + FindRec.Name + '\Desktop';
            if DirExists(DesktopPath) then
            begin
              if CompareText(
                   CommonDesktopShortPath, GetShortName(DesktopPath)) = 0 then
              begin
                Log(Format('Skipping common desktop [%s]', [DesktopPath]));
              end
                else
              begin
                ShortcutPath := DesktopPath + '\My Program.lnk';
                Log(Format(
                  'Found desktop folder for user [%s], creating shortcut [%s]', [
                  FindRec.Name, ShortcutPath]));
                try
                  ShortcutPath := CreateShellLink(
                    ShortcutPath, 'My Program', ExpandConstant('{app}\MyProg.exe'), '',
                    ExpandConstant('{app}'), '', 0, SW_SHOWNORMAL);
                  Log(Format('Shortcut [%s] created', [ShortcutPath]));
                  Inc(ShortcutsCount);
                except
                  Log(Format('Failed to create shortcut: %s', [GetExceptionMessage]));
                end;
              end;
            end;
          end;
        until not FindNext(FindRec);
      finally
        FindClose(FindRec);
      end;

      Log(Format('%d shortcuts created', [ShortcutsCount]));
    end
      else
    begin
      Log(Format('Error listing [%s]', [UsersPath]));
    end;
  end;
end;

如果台式机是本地和公共位置的话,代码才能工作。

如果您需要一个更健壮的解决方案,可以迭代

代码语言:javascript
运行
复制
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

或者使用WMI查询,如:

代码语言:javascript
运行
复制
SELECT * FROM Win32_UserAccount WHERE localAccount = true and disabled = false

Query list of Windows accounts in Inno Setup

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35224772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档