Inno Setup 在所有用户的所有桌面上创建单独的快捷方式 [英] Inno Setup Create individual shortcuts on all desktops of all users
问题描述
我正在使用 Inno Setup 在用户桌面上创建快捷方式:
名称:{commondesktop}Setup";文件名:{app}Setup.exe";工作目录:{pf}Program";图标文件名:{app}Setup.ico"
但是没有管理员权限的用户无法删除此快捷方式,如何授予普通用户权限,删除此图标?图标应该在每个用户的桌面上创建,但用户应该有删除它的权限.
{commondesktop}
快捷方式在公共桌面上共享.所以只有一个快捷方式的副本.
如果您允许用户删除该图标,则当一个用户删除该图标时,其他所有用户都会删除该图标.这就是为什么不允许普通用户修改/删除共享快捷方式的原因.
虽然您可以为该快捷方式的所有用户授予删除权限,但这不是您应该做的.
如果每台机器仅由一个用户使用,请将图标安装到userdesktop
,而不是commondestop
.但这只有在该用户(不是管理员)实际运行安装程序时才有效.有关此问题的一般讨论,请参阅从以管理员身份运行的 Inno Setup 安装程序为当前登录用户安装应用程序.>
没有简单的方法可以将图标安装到所有桌面.您必须使用 Pascal Scripting 并迭代所有配置文件.
简单的方法是迭代C:Users
的子文件夹,在每个用户的子文件夹的Desktop
子文件夹中创建一个快捷方式:
procedure CurStepChanged(CurStep: TSetupStep);无功用户路径:字符串;CommonDesktopShortPath:字符串;桌面路径:字符串;快捷方式:字符串;FindRec: TFindRec;ShortcutsCount:整数;开始{ 一旦文件被安装}如果 CurStep = ssPostInstall 那么开始Log('创建快捷方式');{ 假设普通用户 root(通常是 C:Users)是两个级别的用户 }{ 来自当前用户桌面文件夹 }用户路径:=AddBackslash(ExtractFilePath(RemoveBackslash(ExtractFilePath(RemoveBackslash(ExpandConstant('{userdesktop}'))))));Log(Format('Users root [%s]', [UsersPath]));CommonDesktopShortPath := GetShortName(ExpandConstant('{commondesktop}'));Log(Format('Common Desktop [%s]', [CommonDesktopShortPath]));快捷方式计数:= 0;{ 迭代所有用户 }如果 FindFirst(UsersPath + '*', FindRec) 那么开始尝试重复{ 只是目录,对文件不感兴趣 }如果 FindRec.Attributes 和 FILE_ATTRIBUTE_DIRECTORY <>0 那么开始{ 检查是否有桌面子文件夹 }桌面路径 := 用户路径 + FindRec.Name + 'Desktop';如果 DirExists(DesktopPath) 那么开始如果比较文本(CommonDesktopShortPath, GetShortName(DesktopPath)) = 0 然后开始Log(Format('跳过普通桌面 [%s]', [DesktopPath]));结尾别的开始ShortcutPath := DesktopPath + 'My Program.lnk';日志(格式('为用户 [%s] 找到桌面文件夹,正在创建快捷方式 [%s]', [FindRec.Name, ShortcutPath]));尝试ShortcutPath := CreateShellLink(ShortcutPath, '我的程序', ExpandConstant('{app}MyProg.exe'), '',ExpandConstant('{app}'), '', 0, SW_SHOWNORMAL);Log(Format('Shortcut [%s] created', [ShortcutPath]));Inc(ShortcutsCount);除了Log(Format('创建快捷方式失败:%s', [GetExceptionMessage]));结尾;结尾;结尾;结尾;直到不是 FindNext(FindRec);最后FindClose(FindRec);结尾;Log(Format('%d 个快捷方式已创建', [ShortcutsCount]));结尾别的开始Log(Format('错误列表 [%s]', [UsersPath]));结尾;结尾;结尾;
仅当桌面位于本地且位于公共位置时,代码才有效.
如果您需要更强大的解决方案,您可以迭代
中列出的配置文件HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList
或者使用 WMI 查询,例如:
SELECT * FROM Win32_UserAccount WHERE localAccount = true 和 disabled = false
请参阅Inno Setup 中 Windows 帐户的查询列表.
I'm creating a shortcut on users Desktop with Inno Setup:
Name: "{commondesktop}Setup"; Filename: "{app}Setup.exe"; WorkingDir: "{pf}Program"; IconFilename: "{app}Setup.ico"
But users, with no admin rights, cannot delete this Shortcut, how to grant permissions to regular users, to delete this icon? Icon should be created on every user's desktop, but user should have permission to delete it.
The {commondesktop}
shortcut is shared on a common desktop. So there's only one copy of the shortcut.
If you allow the users to delete, when one user deletes the icon, it's deleted for every other user. That's why regular users are not allowed to modify/delete shared shortcuts.
While you can grant a delete permission to all users to that shortcut, this is not what you should do.
If each machine is used by one user only, install the icon to userdesktop
, not commondestop
. But that works only if that user (not Administrator) actually run the installer. For a general discussion about this problem, see Installing application for currently logged in user from Inno Setup installer running as Administrator.
There's no easy way to install the icons to all desktops. You have to use Pascal Scripting and iterate all profiles.
Easy way is to iterate subfolders of C:Users
, creating a shortcut in Desktop
subfolder of each user's subfolder:
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;
The code will work only, if the desktops are local and in common locations.
If you need a more robust solution, you can iterate profiles listed in
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProfileList
Or use a WMI query like:
SELECT * FROM Win32_UserAccount WHERE localAccount = true and disabled = false
See Query list of Windows accounts in Inno Setup.
这篇关于Inno Setup 在所有用户的所有桌面上创建单独的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!