Jump to content

Recommended Posts

_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
Link to comment
Share on other sites

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:

Link to comment
Share on other sites

  • 2 years later...

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.

Link to comment
Share on other sites

  • 3 years later...
  • 2 months later...

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

 

Link to comment
Share on other sites

  • 3 years later...

@Letraindusoir This is unrelated to this topic that is 10 years old. A ".url" shortcut is just an Ini file though, open it in Notepad. Get it like IniRead($sFilePath, "InternetShortcut", "URL", "")

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

  • 2 weeks later...

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
 Share

×
×
  • Create New...