function PinToTaskbar(const szFilename: String; TaskBar, IsPin: Boolean): Boolean; //szFilename: full path to executable file //TaskBar: False - pin to StartMenu, True - pin to TaskBar //IsPin: False - unpin from TaskBar/StartMenu, True - pin to TaskBar/StartMenu 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; 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; if TaskBar then res := 5386 else res := 5381; end else if TaskBar then res := 5387 else res := 5382; 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[i], 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[i].Name, strVerb) = 0 then begin colVerbs.Item[i].DoIt; Result := True; Break; end; except Exit; end; finally FreeDLL(hInst); end; end; |