Вопрос Ярлык в меню пуск

Mailchik

Старожил
Проверенный
Хамик,
Код:
#define ExePath "{app}\bin\MyProg.exe"

[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application
CreateUninstallRegKey=false

[Files]
Source: compiler:Examples\MyProg.exe; DestDir: {app}\bin;

[Tasks]
Name: PinToTaskBar; Description: {cm:cTaskBarTxt}; MinVersion: 0,6.0;
Name: PinToStartMenu; Description: {cm:cStartMenuTxt}; MinVersion: 0,6.0;

[Languages]
Name: "ru"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "en"; MessagesFile: "compiler:Languages\English.isl"

[CustomMessages]
ru.cTaskBarTxt=Закрепить на панели задач
ru.cStartMenuTxt=Закрепить в меню "Пуск"
en.cTaskBarTxt=Pin to Taskbar
en.cStartMenuTxt=Pin to Start Menu

[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; 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;

procedure CurPageChanged(CurPageID: integer);
begin
  case CurPageID of
    wpFinished: begin
      if IsTaskSelected('PinToTaskBar') then
        PinToTaskbar(ExpandConstant('{#ExePath}'), True, True);
      if IsTaskSelected('PinToStartMenu') then
        PinToTaskbar(ExpandConstant('{#ExePath}'), False, True);
    end;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  instPath: string;
begin
    case CurUninstallStep of
      usUninstall: begin
        PinToTaskbar(ExpandConstant('{#ExePath}'), True, False);
        PinToTaskbar(ExpandConstant('{#ExePath}'), False, False);
      end;
    end;
end;
function PinToTaskbar(const szFilename: String; TaskBar, IsPin: Boolean): Boolean;
//szFilename: путь до exe
//TaskBar: False - в меню "Пуск", True - на панели задач
//IsPin: False - изъять, True - закрепить
 

Xabib2302

Новичок
Mailchik, как сделать так, чтобы ярлыки создавались в зависимости битности ОС
 

Хамик

Старожил
Xabib2302,
Код:
#define MyAppExeName "{app}\bin\CCleaner.exe"

[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application
CreateUninstallRegKey=false

[Files]
Source: CCleaner.exe; DestDir: "{app}\bin"; Check: not IsWin64;
Source: CCleaner64.exe; DestDir: "{app}\bin"; DestName: "CCleaner.exe" Check: IsWin64;

[Tasks]
Name: PinToTaskBar; Description: {cm:cTaskBarTxt}; MinVersion: 0,6.0;
Name: PinToStartMenu; Description: {cm:cStartMenuTxt}; MinVersion: 0,6.0;

[Languages]
Name: "ru"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "en"; MessagesFile: "compiler:Languages\English.isl"

[CustomMessages]
ru.cTaskBarTxt=Закрепить на панели задач
ru.cStartMenuTxt=Закрепить в меню "Пуск"
en.cTaskBarTxt=Pin to Taskbar
en.cStartMenuTxt=Pin to Start Menu

[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; 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;

procedure CurPageChanged(CurPageID: integer);
begin
  case CurPageID of
        wpFinished:
        begin
      if IsTaskSelected('PinToTaskBar') then
        PinToTaskbar(ExpandConstant('{#MyAppExeName}'), True, True);
      if IsTaskSelected('PinToStartMenu') then
        PinToTaskbar(ExpandConstant('{#MyAppExeName}'), False, True);
      if IsTaskSelected('PinToTaskBar') then
        PinToTaskbar(ExpandConstant('{#MyAppExeName}'), True, True);
      if IsTaskSelected('PinToStartMenu') then
        PinToTaskbar(ExpandConstant('{#MyAppExeName}'), False, True);
    end;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  instPath: string;
begin
    case CurUninstallStep of
      usUninstall: begin
      PinToTaskbar(ExpandConstant('{#MyAppExeName}'), True, False);
      PinToTaskbar(ExpandConstant('{#MyAppExeName}'), False, False);
      PinToTaskbar(ExpandConstant('{#MyAppExeName}'), True, False);
      PinToTaskbar(ExpandConstant('{#MyAppExeName}'), False, False);
      end;
    end;
end;
 

Хамик

Старожил
Xabib2302, что не то? По конкретней, если хотите чтобы вам помогли.
Пробуйте:
Код:
#define MyAppExeName "CCleaner.exe"

[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application
CreateUninstallRegKey=false

[Files]
Source: CCleaner.exe; DestDir: "{app}"; Check: not IsWin64;
Source: CCleaner64.exe; DestDir: "{app}"; DestName: "CCleaner.exe"; Check: IsWin64;

[Tasks]
Name: PinToTaskBar; Description: {cm:cTaskBarTxt}; MinVersion: 0,6.0;
Name: PinToStartMenu; Description: {cm:cStartMenuTxt}; MinVersion: 0,6.0;

[Languages]
Name: "ru"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "en"; MessagesFile: "compiler:Languages\English.isl"

[CustomMessages]
ru.cTaskBarTxt=Закрепить на панели задач
ru.cStartMenuTxt=Закрепить в меню "Пуск"
en.cTaskBarTxt=Pin to Taskbar
en.cStartMenuTxt=Pin to Start Menu

[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; 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;

procedure CurPageChanged(CurPageID: integer);
begin
  case CurPageID of
        wpFinished:
        begin
      if IsTaskSelected('PinToTaskBar') then
        PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), True, True);
      if IsTaskSelected('PinToStartMenu') then
        PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), False, True);
      if IsTaskSelected('PinToTaskBar') then
        PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), True, True);
      if IsTaskSelected('PinToStartMenu') then
        PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), False, True);
    end;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
  instPath: string;
begin
    case CurUninstallStep of
      usUninstall: begin
      PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), True, False);
      PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), False, False);
      PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), True, False);
      PinToTaskbar(ExpandConstant('{app}\{#MyAppExeName}'), False, False);
      end;
    end;
end;
 
Последнее редактирование:
Сверху