Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resolving shortcut files
#2
Function UpdateShortcut
Code:
Copy      Help
;/
function# $lnkfile [noUI] [timeout]

;Updates shortcut's target if it is moved or renamed.
;It is not error to call this function for healthy shortcuts too.
;Returns 1 if successful.


;lnkfile - shortcut file.
;noUI - do not display a dialog.
;timeout - if noUI is nonzero, the max number of milliseconds to search. Default or 0 - 3000.


;EXAMPLE
;str lnk="$desktop$\test.lnk"
;if(!UpdateShortcut(lnk)) out "invalid shortcut: %s" lnk



interface# IShellLinkA :IUnknown
,GetPath($pszFile cch WIN32_FIND_DATAA*pfd fFlags)
,GetIDList(ITEMIDLIST**ppidl)
,SetIDList(ITEMIDLIST*pidl)
,GetDescription($pszName cch)
,SetDescription($pszName)
,GetWorkingDirectory($pszDir cch)
,SetWorkingDirectory($pszDir)
,GetArguments($pszArgs cch)
,SetArguments($pszArgs)
,GetHotkey(@*pwHotkey)
,SetHotkey(@wHotkey)
,GetShowCmd(*piShowCmd)
,SetShowCmd(iShowCmd)
,GetIconLocation($pszIconPath cch *piIcon)
,SetIconLocation($pszIconPath iIcon)
,SetRelativePath($pszPathRel dwReserved)
,Resolve(hwnd fFlags)
,SetPath($pszFile)
,{000214EE-0000-0000-C000-000000000046}
interface# IPersist :IUnknown
,GetClassID(GUID*pClassID)
,{0000010c-0000-0000-C000-000000000046}
interface# IPersistFile :IPersist
,IsDirty()
,Load(@*pszFileName dwMode)
,Save(@*pszFileName fRemember)
,SaveCompleted(@*pszFileName)
,GetCurFile(@**ppszFileName)
,{0000010b-0000-0000-C000-000000000046}
def CLSID_ShellLink uuidof("{00021401-0000-0000-C000-000000000046}")
def SLR_UPDATE 0x4
def SLR_NO_UI 0x1

IShellLinkA sl._create(CLSID_ShellLink)
IPersistFile pf=+sl
str s.expandpath(lnkfile)
pf.Load(+s.unicode 0); err ret
int flags=SLR_UPDATE; if(noUI) flags|SLR_NO_UI; flags|timeout<<16
sl.Resolve(0 flags); err ret
ret !_hresult

You can call it before GetShortcutInfoEx (easier), or when GetShortcutInfoEx returns invalid path (maybe a bit faster).


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)