Jump to content
Ascend4nt

_FileGetShortcutEx

Recommended Posts

Ascend4nt

_FileGetShortcutEx

This UDF will return shortcut (.LNK) file information for more advanced shortcuts that AutoIt's built-in FileGetShortcut() chokes on.

The following types of shortcuts can be retrieved using this function:

  • MSI Advertised Shortcuts
  • URL (website) Shortcuts that are embedded (rather than put in a .URL file)
  • Special GUID Shell Item Shortcuts. This is only one level deep at the moment, so it will only read the base Folder GUID (For example: shortcuts to 'My Computer', 'Recycle Bin' return fine)
  • UNC Shortcuts ("PCNAME"). This is also only one level deep currently, so "PCNAMEFolder" shortcuts will fail
  • (as well as regular shortcuts, of course)

Operation is simple: call '_FileGetShortcutEx("filename")' to get an array that is arranged the same as FileGetShortcut().

Included in the ZIP are two examples of shortcuts that AutoIt will fail on, but this function will work on. I don't have any MSI Advertised shortcut examples, but I believe Microsoft Office and ACDSee shortcuts both use these shortcuts types which return wonky results using AutoIt's function.

Thanks go out to Prog@ndy for the original '_FileGetShortcutEx' function and MSI shortcut code (which I converted for Unicode). See my original post here for his code.

*Shortcut Key retrieval*

This was requested on the Help board, and I thought it was a good idea to include it here.  If you need to grab a shortcut's associated Shortcut Key, you can use the below code, assuming you already know beforehand that the file is a shortcut file:

$sShortcutFile = "C:\MyShortcut.lnk"
$nShortcutKey = Number(StringToBinary(StringMid(FileRead($sShortcutFile, 68), 65, 4)))
ConsoleWrite("Shortcut key = " & $nShortcutKey & @CRLF)

 

The format of the key is described under IShellLink::GetHotkey, and I've included code that converts most key combos in >this post.

*Special note on 'Normal' Internet shortcuts: While this UDF only looks at .LNK shortcuts (what you use FileGetShortcut() with), some confuse .URL Internet shortcuts with these types, so I decided I'd put a solution for those interested on how to get a URL Internet shortcut. It's actually so simple it can be done in one line, so here it is (note the .URL extension):

$sURL=IniRead(@UserProfileDir&"\Favorites\Google.URL","InternetShortcut","URL","")

 

Ascend4nt's AutoIT Code License agreement:

no license - just be a good person and credit other people for their work, yeh?

Download the ZIP from my site

Edited by Ascend4nt
  • Like 1

Share this post


Link to post
Share on other sites
KaFu
Ascend4nt

haha you're fast. Bear in mind this was sort of an old script, and I didn't do much in the way of cleanup. I just decided to post it as-is since I wanted to help someone out. Didn't think it'd be of much use to anyone else, but l guess I was wrong :blink:

Share this post


Link to post
Share on other sites
Ascend4nt

Semi-sorta update:  Included code in the 1st post to read the shortcut key from a shortcut file.

Also, I have a few >Key-To-String functions on the Help Forum that work with translating most shortcut key combinations.

Share this post


Link to post
Share on other sites
odaylton

Translated by Google. Sorry for any mistakes.
I made a post here showing in practice this feature I hope you enjoy

 

 

Share this post


Link to post
Share on other sites
odaylton

Text translated from Portuguese by google - please apologize for any errors

 

I would firstly like to thank the initiative to spread this knowledge ...

I noticed a small flaw in the routine regarding the variable "$ bExpandEnvStrings" which in some cases I used it with the value "TRUE" but I noticed that the answers were not always correct, but with the variables of DOS% XXX%

 

And also in Windows 7 the shortcuts of the games provided by microsoft were not found but the location of the icons did

I hope that if possible try to solve the game case in a less simplistic way

Then include the lines below

Func _FileGetShortcutEx($sLNKFile, $bExpandEnvStrings = False)
    Local $aShortcutInfo[7]
    $aShortcutInfo = FileGetShortcut($sLNKFile)
    ;The array returned from this function is a single dimension array containing the following elements:
    ;$aArray[0] = Shortcut target path
    ;$aArray[1] = Working directory
    ;$aArray[2] = Arguments
    ;$aArray[3] = Description
    ;$aArray[4] = Icon filename
    ;$aArray[5] = Icon index
    ;$aArray[6] = The shortcut state (@SW_SHOWNORMAL, @SW_SHOWMINNOACTIVE, @SW_SHOWMAXIMIZED)



    ; MsgBox(0,"LNK","0:" & $aShortcutInfo[0] & @CRLF & "1:" & $aShortcutInfo[1] & @CRLF & _
    ;   "2:" & $aShortcutInfo[2] & @CRLF & "3:" & $aShortcutInfo[3] & "4:" & $aShortcutInfo[4])
    If @error Then
        SetError(@error, 0)
        ;17/02/15  incrementei isso
        If $bExpandEnvStrings Then _ArrayExpandEnvStr($aShortcutInfo, 0, 4)
        Return $aShortcutInfo
    EndIf
    Local $msitest = _MSIShortcutTarget($sLNKFile)
    If Not @error Then $aShortcutInfo[0] = $msitest
    ; Shortcut STILL not yielding correct results?
    ; NOTE: Please use Unicode so that Unicode shortcuts are read/processed properly!
    If $aShortcutInfo[0] = "" Then
        ; Try to see if its a special UNC-only, URL-only, or GUID-only LNK file
        Local $sResult = _FileGetGUIDShortcuts($sLNKFile)
        ;AutoIt_Debugger_Command:Enable_Debug
        
        If $sResult <> "" Then
            $aShortcutInfo[0] = $sResult
        Else
            
            ;17/02/15  incrementei isso
            If $aShortcutInfo[4] <> "" Then 
                $aShortcutInfo[0] = $aShortcutInfo[4]
            Else
                MsgBox(0, "Este não deu", _
                    "Os dados do atalho [" & $sLNKFile & "] foram insatisfatorios:" & @CRLF & _
                    "aArray[0] = Shortcut target path[" & $aShortcutInfo[0] & "]" & @CRLF & _
                    "aArray[1] = Working directory[" & $aShortcutInfo[1] & "]" & @CRLF & _
                    "aArray[2] = Arguments[" & $aShortcutInfo[2] & "]" & @CRLF & _
                    "aArray[3] = Description[" & $aShortcutInfo[3] & "]" & @CRLF & _
                    "aArray[4] = Icon filename[" & $aShortcutInfo[4] & "]" & @CRLF & _
                    "aArray[5] = Icon index[" & $aShortcutInfo[5] & "]" & @CRLF & _
                    "aArray[6] = The shortcut state[" & $aShortcutInfo[6] & "]")
            
            EndIf
        EndIf
        ;AutoIt_Debugger_Command:Disable_Debug
        
        SetError(@error, @extended)
        ;17/02/15  incrementei isso
        If $bExpandEnvStrings Then _ArrayExpandEnvStr($aShortcutInfo, 0, 4)
        Return $aShortcutInfo
    EndIf
    If $bExpandEnvStrings Then _ArrayExpandEnvStr($aShortcutInfo, 0, 4)

    Return $aShortcutInfo
EndFunc   ;==>_FileGetShortcutEx

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • sosimple
      By sosimple
      Is this possible with autoit?
      What I want to do:
      Create a Desctop windows shortcut to run an executable application created with autoit, which shortcut would have some parameters which will send as a variable to the aplicagion .
      For example:
      Create an app : ExampleAppCreatedByAutoit.exe
      Run this with a shortcut which has:  "C:/ExampleAppCreatedByAutoit.exe" -option1
      What I want to do is the ExampleAppCreatedByAutoit.exe take the option1 and do something like this: Shellexecute("c:\myfolder\option1.exe")
      Can I do that?
      Thanks,
    • Rocker
      By Rocker
      I apologize for my poor coding skills, but only on occasion do I have a need to automate a repetitious task to save time.  In a nutshell the following code is supposed to go to a website, save the site using Scrapbook (a plugin used by an older version of Firefox), rename the folder in Windows Explorer that Scrapbook assigns a random name for and then moves on to the next website, of which there are hundreds.  Everything works, except after the address bar gets populated with the URL, it's like the ENTER key never gets pushed.  The weird thing is, this worked yesterday before I left to go home and when I came in this morning it didn't work.  The next thing I'll be trying to learn is to loop this with a the list of the websites.  Thank you for your help!
      WinActivate( "[CLASS:MozillaWindowClass]" ) ;Apply focus to the open Mozilla firefox window Sleep(500) Send("^k") ;Apply focus to the address bar Sleep(500) Send("www.WEBSITE.com {ENTER}") ;Send the website to the address bar Sleep(10000) ;Wait for the website to fully open Send("!c") ;Opens the drop down menu for Scrapbook Sleep(2000) Send("{ENTER}") ;Selects the default drop down selection of save Sleep(20000) WinActivate( "[CLASS:CabinetWClass]" ) ;Applies focus to the open Windows Explorer window where the websites are saved Sleep(1000) Send("{SPACE}") ; Selects a folder in the folders list Sleep(200) Send("{HOME}") ;Moves to the top folder Sleep(200) Send("{F2}") ;Keyboard shortcut to rename the folder Sleep(200) Send("www.WEBSITE.com {ENTER}") ;Applies the new name to the folder  
    • nacerbaaziz
      By nacerbaaziz
      Hello all
      I have a question please
      I have a link to an .exe file
      for example this link
      https://www.nvaccess.org/files/nvda/releases/2017.1/NVDA_2017.1.exe
      I want to check if the link is exists orno
      surely  Without downloading the file
      is there any  function or a way to  do this?
      Thanks in advance
    • satanico64
      By satanico64
      hi guys, how are you ??  fine? good...
      Here is a little question: is it possible to know whish shortcut has been used to launch my autoit app ?
      i'm quite sure that there's nothing to do with autoit, but mostly windows ...
       
      My context: i have an app accessed from the network by my user.
      In my app i use FileCreateShortcut to point to \\myfileserver\myapp.exe
      Soon, in october, they are going to change my fileserver, so my app will be on \myNEWfileserver\myapp.exe
      So in my code, i just rewrite my shortcut on the desktop's user. Everything works fine.
      BUT..some users have several shortcut for my app (they just manually create another shortcut which i don't know the name).
      So maybe they don't use my shortcut but their own ...
      => i know I could list all file on desktop, and for all the .lnk i check if destination is myapp.exe and modify the path but do you see another way ?
       
      thanks
      have fun !
       
    • ur
      By ur
      I am trying to launch the shortcut through autoit, but I am getting below error.
      [Window Title] C:\Windows\system32\cmd.exe /c start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\erwin\erwin Mart Server r9.8 (64-bit)\Create MartServer Service.lnk" [Content] Windows cannot find 'C:\Windows\system32\cmd.exe /c start "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\erwin\erwin Mart Server r9.8 (64-bit)\Create MartServer Service.lnk"'. Make sure you typed the name correctly, and then try again. [OK] Launching the target directly is not feasible as it is dynamic.
      I tried.
      $r = ShellExecute(@ComSpec & " /c " & "start """& @ProgramsCommonDir & "\erwin\erwin Mart Server r9.8 (64-bit)\Create MartServer Service.lnk""")
       
      and also Run and RUnwait
       
       
×