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

Share this post


Link to post
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:


Share this post


Link to post
Share on other sites

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

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

@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

Share this post


Link to post
Share on other sites
On ‎5‎/‎26‎/‎2020 at 8:10 PM, seadoggie01 said:

@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", "")

Now I Got it,Most thanks For seadoggie01 !

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jahar
      Hi,
      I am new to Autoit, Kindly guide me. I wanted to send a message with HTTP/GET to the URL https://ghsff.it/. How to do so?
    • By HariKara
      I have a script that seems to launch perfectly fine with IECreate, however, I want to launch the Browser and a specific URL with the RunAs command. I fairly new to AutoIT and wanted to know if someone can point me in the right direction.
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = _IECreate($sURL)
      The above launches the website correctly with the correct URL, however, I have tried the below and this fails to load and browser?
      #include <AutoItConstants.au3>
      ;========================
      $oSleep = "200"
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = RunAs($args("username"), $args("domain"), $args("logonpassword"), "", "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://somewebsite.com/DODA/admin/job.aspx")
      _IELoadWait($oIE)
       
      I get the following error back?
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
    • By nacerbaaziz
      hello sirs
      please i want to use the WinHttp to get the google drive file title using the api
      i searched in the forom but i didn't found any Google drive api UDF
      for that i liked to ask you for that
      i had read the google drive api documentation but i couldn't do it
      please help me
      here is the api doc
      note i've got the apikey and i have the file id
      what i want is to get the title of the file (the file name)
      because i want to download the files from the google drive using the autoit
      please help me for that
      am sorry because i didn't gave you any example or what i tried but all what tried was  failed
      thanks in advance
    • By nacerbaaziz
      hello sirs
      i've some questions about StringRegExpReplace i hope you can help me
       
      i tried to make a function that give me the host of the url and other give me the url with out host
      for example i've this link
      https://www.example.com/vb/result.php
      i need the first give me the
      example.com
      and the other give me 
      /vb/result.php
      i find that
      $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page)  
      but i found some problems i need your help to correct it
      first: when i get the host if the url has www i want to remove it
      second: if the url with out host did not have other things 
      i need the result to be ""
      e.g
      https://www.example.com
      the first i want it
      example.com
      and the second i want it to be ""
      i hope that you can help me
      thanks in advance
×
×
  • Create New...