Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Аватара для habib2302

Ветеран


Сообщения: 862
Благодарности: 102

Профиль | Отправить PM | Цитировать


Beavimo,
Код:

Код: Выделить весь код
[code]
//PinToTaskbar
function PinToTaskbar(const FileName: string; IsPin: Boolean): Boolean;
// FileName : full path to executable file
// IsPin    : False - unpin from TaskBar, True - pin to TaskBar
var
  ShellApp: Variant;
  Verb: string;
begin
  Result := False;
  if not FileExists(FileName) then Exit;
  try
    if IsPin then
      Verb := 'taskbarpin' else
      Verb := 'taskbarunpin';
    ShellApp := CreateOleObject('Shell.Application');
    ShellApp.Windows.Item.Document.Application.NameSpace(ExtractFileDir(FileName)).ParseName(ExtractFileName(FileName)).InvokeVerb(Verb);
    Result := True;
  except
    ShowExceptionMessage;
  end;
end;

//PinToStartMenu
function PinToStartMenu(const FileName: string; const IsPin: Boolean): Boolean;
// FileName : full path to exe- or lnk-file
// IsPin    : False - unpin from StartMenu, True - pin to StartMenu
var
  ShellApp, FolderItem: Variant;
  Verb, LnkName: string;
begin
  Result := False;
  if not FileExists(FileName) then Exit;
  try
    ShellApp := CreateOleObject('Shell.Application');
    FolderItem := ShellApp.Windows.Item.Document.Application.NameSpace(ExtractFileDir(FileName)).ParseName(ExtractFileName(FileName));
    if GetWindowsVersion < $06020000 then // below Windows 8
    begin
      if IsPin then
        Verb := 'startpin' else
        Verb := 'startunpin';
      FolderItem.InvokeVerb(Verb);
      Result := True;
    end
    else  // Windows 8 and above
    begin
      if not FolderItem.IsLink then
      begin
        LnkName := FolderItem.ExtendedProperty('FileDescription');
        if LnkName = '' then
          LnkName := ExtractFileName(FileName);
        LnkName := ExpandConstant('{commonprograms}\') + ChangeFileExt(LnkName, '.lnk');
        if IsPin then
          Result := not FileExists(LnkName) and
            FileExists(CreateShellLink(LnkName, '', FileName, '', '', '', 0, SW_SHOWNORMAL))
        else
          Result := DeleteFile(LnkName);
      end
      else
      begin
        LnkName := ExpandConstant('{commonprograms}\') + ExtractFileName(FolderItem.Path);
        if IsPin then
          Result := not FileExists(LnkName) and
            FileCopy(FolderItem.Path, LnkName, False)
        else
          Result := DeleteFile(LnkName);
      end;
    end;
  except
    ShowExceptionMessage;
  end;
end;

-------
Помог? От "Полезное сообщение" не откажусь!!!


Отправлено: 14:11, 09-02-2020 | #537