我創建的用戶桌面的快捷方式與創新安裝的所有桌面創建單獨的快捷方式: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副本? –