Описание функции
GetShellLinkTargetPath
Возвращает путь к программе из ярлыка.
GetShellLinkTargetPath(shellLinkFilePath$)
Параметры
shellLinkFilePath$ | Путь к ярлыку |
Возвращаемое значение
Успех: | Возвращает путь |
Ошибка: | Возвращает пустую строку "" |
Пример
EnableExplicit
; https://www.purebasic.fr/english/viewtopic.php?p=575361#p575361
Procedure.s GetShellLinkTargetPath(shellLinkFilePath$)
Protected Path$ = Space(#MAX_PATH)
Protected linkFile.IPersistFile
Protected shellLink.IShellLinkW
Protected Fine = 0
CoInitialize_(0)
If CoCreateInstance_(?CLSID_ShellLink, 0, 1, ?IID_IShellLink, @shellLink) = #S_OK
If shellLink\QueryInterface(?IID_IPersistFile, @linkFile) = #S_OK
If linkFile\Load(shellLinkFilePath$, 0) = #S_OK
If shellLink\Resolve(0, 1) = #S_OK
shellLink\GetPath(@Path$, #MAX_PATH, 0, 0)
Fine = 1
EndIf
EndIf
LinkFile\Release()
EndIf
shellLink\Release()
EndIf
CoUninitialize_()
If Fine And Asc(Path$) <> 0 And Asc(Path$) <> 32
ProcedureReturn Path$
Else
ProcedureReturn ""
EndIf
DataSection
CLSID_ShellLink:
; 00021401-0000-0000-C000-000000000046
Data.l $00021401
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
IID_IShellLink:
CompilerIf #PB_Compiler_Unicode
; IID_IShellLinkW
; {000214F9-0000-0000-C000-000000000046}
Data.l $000214F9
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
CompilerElse
; 000214EE-0000-0000-C000-000000000046
Data.l $000214EE
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
CompilerEndIf
IID_IPersistFile:
; 0000010b-0000-0000-C000-000000000046
Data.l $0000010b
Data.w $0000,$0000
Data.b $C0,$00,$00,$00,$00,$00,$00,$46
EndDataSection
EndProcedure
Debug GetShellLinkTargetPath(GetUserDirectory(#PB_Directory_AllUserData) + "Microsoft\Windows\Start Menu\Programs\Accessories\Paint.lnk")