Jump to content

Recommended Posts

Posted (edited)

_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

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

Posted

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:

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

  • 2 years later...
Posted

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.

My contributions:

  Reveal hidden contents

Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFsProcess CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen)Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery

Wrappers/Modifications of others' contributions:

_DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity)

UDF's added support/programming to:

_ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne)

(All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)

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

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

 

  • 3 years later...
Posted

@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.

  Reveal hidden contents
  • 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
×
×
  • Create New...