Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Общие вопросы Delphi
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 25.07.2009, 02:50   #1
Zeraim
Ra-Ra ?
Форумчанин
 
Аватар для Zeraim
 
Регистрация: 06.03.2008
Сообщений: 286
По умолчанию lnk, а точнее как узнать путь к exe.

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

Последний раз редактировалось Zeraim; 25.07.2009 в 02:52.
Zeraim вне форума Ответить с цитированием
Старый 25.07.2009, 08:10   #2
Kotofff
Участник клуба
 
Аватар для Kotofff
 
Регистрация: 11.01.2009
Сообщений: 1,917
По умолчанию

Держи. Изучай. Спрашивай.
Вложения
Тип файла: rar ПутьИзЯрлыка.rar (7.8 Кб, 34 просмотров)
"Заряженному танку в дуло не смотрят" @Dekmer in WoT
Kotofff вне форума Ответить с цитированием
Старый 25.07.2009, 12:33   #3
Terran
Участник клуба
 
Аватар для Terran
 
Регистрация: 28.11.2007
Сообщений: 1,521
По умолчанию

Вот ещё может пригодится. Код для получения информации о ярлыке:
Код:
Uses
shlobj,
comobj,
activex,
commctrl;

type
pshelllinkinfostruct = ^tshelllinkinfostruct;
tshelllinkinfostruct = record
fullpathandnameoflinkfile: array[0..max_path] of char;
fullpathandnameoffiletoexecute: array[0..max_path] of char;
paramstringsoffiletoexecute: array[0..max_path] of char;
fullpathandnameofworkingdirectroy: array[0..max_path] of char;
description: array[0..max_path] of char;
fullpathandnameoffilecontiningicon: array[0..max_path] of char;
iconindex: integer;
hotkey: word;
showcommand: integer;
finddata: twin32finddata;
end; 

procedure getlinkinfo(lpshelllinkinfostruct: pshelllinkinfostruct); 
var 
shelllink: ishelllink;
persistfile: ipersistfile; 
anobj: iunknown; 
begin 
// access to the two interfaces of the object 
anobj := createcomobject(clsid_shelllink); 
shelllink := anobj as ishelllink; 
persistfile := anobj as ipersistfile; 

// opens the specified file and initializes an object from the file contents. 
persistfile.load(pwchar(widestring(lpshelllinkinfostruct^.fullpathandnameoflinkfile)), 0); 
with shelllink do 
begin 
// retrieves the path and file name of a shell link object. 
getpath(lpshelllinkinfostruct^.fullpathandnameoffiletoexecute, 
sizeof(lpshelllinkinfostruct^.fullpathandnameoflinkfile), 
lpshelllinkinfostruct^.finddata,
slgp_uncpriority); 

// retrieves the description string for a shell link object. 
getdescription(lpshelllinkinfostruct^.description, 
sizeof(lpshelllinkinfostruct^.description)); 

// retrieves the command-line arguments associated with a shell link object. 
getarguments(lpshelllinkinfostruct^.paramstringsoffiletoexecute,
sizeof(lpshelllinkinfostruct^.paramstringsoffiletoexecute)); 

// retrieves the name of the working directory for a shell link object. 
getworkingdirectory(lpshelllinkinfostruct^.fullpathandnameofworkingdirectroy, 
sizeof(lpshelllinkinfostruct^.fullpathandnameofworkingdirectroy)); 

// retrieves the location (path and index) of the icon for a shell link object.
geticonlocation(lpshelllinkinfostruct^.fullpathandnameoffilecontiningicon, 
sizeof(lpshelllinkinfostruct^.fullpathandnameoffilecontiningicon), 
lpshelllinkinfostruct^.iconindex); 

// retrieves the hot key for a shell link object. 
gethotkey(lpshelllinkinfostruct^.hotkey); 

// retrieves the show (sw_) command for a shell link object. 
getshowcmd(lpshelllinkinfostruct^.showcommand); 
end; 
end; 

procedure tform1.button1click(sender: tobject); 
const
br = #13#10; 
var 
linkinfo: tshelllinkinfostruct; 
s: string; 
begin 
fillchar(linkinfo, sizeof(linkinfo), #0); 
linkinfo.fullpathandnameoflinkfile := 'c:winntprofilesuserdesktopfilename.lnk';
getlinkinfo(@linkinfo); 
with linkinfo do 
s := fullpathandnameoflinkfile + br + 
fullpathandnameoffiletoexecute + br + 
paramstringsoffiletoexecute + br + 
fullpathandnameofworkingdirectroy + br + 
description + br +
fullpathandnameoffilecontiningicon + br + 
inttostr(iconindex) + br + 
inttostr(lobyte(hotkey)) + br + 
inttostr(hibyte(hotkey)) + br + 
inttostr(showcommand) + br + 
finddata.cfilename + br +
finddata.calternatefilename; 
memo1.lines.add(s);
end;
Всегда рад помочь!
Terran вне форума Ответить с цитированием
Старый 25.07.2009, 13:44   #4
Zeraim
Ra-Ra ?
Форумчанин
 
Аватар для Zeraim
 
Регистрация: 06.03.2008
Сообщений: 286
По умолчанию

Kotoff, спасибо что с примером, так как-то легче сообразить.
Но хочу кое что уточнить:
Код:
if (fileexists(Linkfilename) = false) then exit;
    MyObject := CreateComObject(CLSID_ShellLink);
    MyPFile := MyObject as IPersistFile;
    MySLink := MyObject as IShellLink;
    StringToWideChar(LinkFileName, WidePath, SizeOf(WidePath));
    MyPFile.Load(WidePath, STGM_READ);
    MySLink.GetPath(Buff, Max_PATH, FileInfo, SLGP_UNCPRIORITY);
    Result := buff;
Как я понял, мы создаём в памяти линк, потом грузим в него инфу из уже существующего, и вытаскиваем то что нам нужно?
И еще:
Код:
if (fileexists(Linkfilename) = false) then exit;
В большинстве примеров которые видел (не только по данной теме), пишется вот такой вот выход.
Чем он хуже такого условия ?
Код:
if fileexists(Linkfilename) then ....;
Zeraim вне форума Ответить с цитированием
Старый 25.07.2009, 13:59   #5
Kotofff
Участник клуба
 
Аватар для Kotofff
 
Регистрация: 11.01.2009
Сообщений: 1,917
По умолчанию

Цитата:
Чем он хуже такого условия ?
Немного разные условия.
Код:
if (fileexists(Linkfilename) = false) then exit;// если файла нет - выход
Код:
if fileexists(Linkfilename) then ....;// если файл существует (FileExists возвращает true)  - то ...
"Заряженному танку в дуло не смотрят" @Dekmer in WoT
Kotofff вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Как узнать путь где щас мой exe zotox Помощь студентам 2 26.03.2009 23:38
Как узнать полный путь к *.ехе файлу SeЯgey Помощь студентам 3 27.05.2008 09:46
Как указать путь компилируемуму exe файлу shurik_7866 Общие вопросы Delphi 2 18.07.2007 23:24
Как узнать путь запуска программы? John_chek Общие вопросы Delphi 5 04.05.2007 10:31
как узнать путь запущенного сервиса Alar Общие вопросы Delphi 0 30.10.2006 11:18