我创建的用户桌面的快捷方式与创新安装的所有桌面创建单独的快捷方式:Inno Setup的所有用户
Name: "{commondesktop}\Setup"; Filename: "{app}\Setup.exe"; WorkingDir: "{pf}\Program"; IconFilename: "{app}\Setup.ico"
但用户没有管理员权限,无法删除此快捷方式,如何授权对普通用户的权限,删除这个图标?图标应该在每个用户的桌面上创建,但用户应该有权删除它。
我创建的用户桌面的快捷方式与创新安装的所有桌面创建单独的快捷方式:Inno Setup的所有用户
Name: "{commondesktop}\Setup"; Filename: "{app}\Setup.exe"; WorkingDir: "{pf}\Program"; IconFilename: "{app}\Setup.ico"
但用户没有管理员权限,无法删除此快捷方式,如何授权对普通用户的权限,删除这个图标?图标应该在每个用户的桌面上创建,但用户应该有权删除它。
{commondesktop}
快捷方式共享于共同桌面。所以只有一个快捷方式的副本。
如果允许用户删除,当一个用户删除该图标时,会删除其他每个用户。这就是为什么普通用户不允许修改/删除共享快捷方式的原因。
虽然您可以向所有用户授予删除权限,但这不是您应该执行的操作。
如果每个机用于由一个用户只,图标安装到userdesktop
,不commondestop
。但是,只有该用户(不是管理员)实际运行安装程序时才有效。有关此问题的一般性讨论,请参阅Installing application for currently logged in user from Inno Setup installer running as Administrator。
没有简单的方法将图标安装到所有桌面。您必须使用Pascal脚本并迭代所有配置文件。
简单的方法是迭代的C:\Users
子文件夹,在每个用户的子文件夹的Desktop
子文件夹中创建快捷方式:
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;
代码只会工作,如果桌面本地和共同的位置。
如果你需要一个更强大的解决方案,可以在迭代
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
上市资料或使用WMI查询,如:
SELECT * FROM Win32_UserAccount WHERE localAccount = true and disabled = false
如果我将使用'userdesktop'而不是'commondestop',快捷方式将仅在管理员桌面中创建。因为我从管理员名称安装它。那就是问题所在。 –
我已经添加了一个代码来创建所有桌面上的短小。只有当桌面位于本地时,它才能工作。 –
谢谢,这段代码运行良好。但它也会在公共桌面上创建快捷方式,并且桌面上会有2个快捷方式:一个用户可以删除,另一个则不能删除。 –
@马丁我在域中的10台电脑。每个域用户只使用他的电脑。可以删除某些特定PC上的所有用户的桌面快捷方式。或者,也许有一种方法可以为所有用户桌面创建一个shortcat副本? –