Вопрос How to add an optional shortcut to taskbar windows 7?

nizcoz

Участник
How to add an optional shortcut to taskbar on windows 7 with inno setup? (and when i uninstall the program, uninstall the shortcut too, obviously).
 

vint56

Ветеран
Проверенный
nizcoz, Пример от Хамик,
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Languages]
Name: "default"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "pin"; Description: "Закрепить ярлык на панели задач"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Program Files\Inno Setup 5 Ultra\Examples\MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion

[Code ]
const
LOAD_LIBRARY_AS_DATAFILE = $2;

#define A = (Defined UNICODE) ? "W" : "A"

function LoadLibraryEx(lpFileName: String; hFile: THandle; dwFlags: DWORD): THandle; external 'LoadLibraryEx{#A}@kernel32.dll stdcall';
function LoadString(hInstance: THandle; uID: SmallInt; var lpBuffer: Char; nBufferMax: Integer): Integer; external 'LoadString{#A}@user32.dll stdcall';
function SHGetNewLinkInfo(pszLinkTo, pszDir: String; var pszName: Char; var pfMustCopy: Longint; uFlags: UINT): BOOL; external 'SHGetNewLinkInfo{#A}@shell32.dll stdcall';
function PinToTaskbar(const szFilename: String; IsPin: Boolean): Boolean;

var
hInst: THandle;
buf: array [0..255] of Char;
i, res: Integer;
strLnk, strVerb: String;
objShell, colVerbs: Variant;
begin
Result := False;
if (GetWindowsVersion < $06010000) or not FileExists(szFilename) then Exit; { below Windows 7 }

{ String resources }
if IsPin then
begin
if SHGetNewLinkInfo(szFilename, ExpandConstant('{tmp}'), buf[0], res, 0) then
begin
while buf[Length(strLnk)] <> #0 do Insert(buf[Length(strLnk)], strLnk, Length(strLnk)+1);
if FileExists(ExpandConstant('{userappdata}\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\') + ExtractFileName(strLnk)) then Exit;
end;
res := 5386; { Pin to Tas&kbar }
end else res := 5387; { Unpin from Tas&kbar }

{ Load string resource }
hInst := LoadLibraryEx(ExpandConstant('{sys}\shell32.dll'), 0, LOAD_LIBRARY_AS_DATAFILE);
if hInst <> 0 then
try
for i := 0 to LoadString(hInst, res, buf[0], 255)-1 do Insert(buf, strVerb, i+1);
try
objShell := CreateOleObject('Shell.Application');
colVerbs := objShell.Namespace(ExtractFileDir(szFilename)).ParseName(ExtractFileName(szFilename)).Verbs;
for i := 1 to colVerbs.Count do if CompareText(colVerbs.Item.Name, strVerb) = 0 then
begin
colVerbs.Item.DoIt;
Result := True;
Break;
end;
except
Exit;
end;
finally
FreeDLL(hInst);
end;
end;

procedure CurPageChanged(CurPageID: integer);
begin
case CurPageID of
wpFinished: begin
if IsTaskSelected('Pin') then
PinToTaskbar(ExpandConstant('{app}\MyProg.exe'), True);
end;
end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
instPath: string;
begin
case CurUninstallStep of
usUninstall: begin
PinToTaskbar(ExpandConstant('{app}\MyProg.exe'), False);
end;
end;
end;
 

SBalykov

Старожил
Виталий,
у меня сложилось такое впечатление, что от тебя ждут, когда ты не выдержишь и напишешь данному товарищу скрипт полностью ...
 
Сверху