zeenmakr Posted September 18, 2020 Share Posted September 18, 2020 objective: get url from *.lnk files that were created with FileCreateShortcut(). just found out been creating lnk wrong but when double click on it it does open up in the default browser. the only problem is it fails to retrieve url with FileGetShortcut(). there are lots of shortcuts that need to retrieve url from and wondering if there is any chance of an alternative way to get it? any thoughts would be appreciated, thanks, also see screenshots bellow is the function used to demonstrate both the wrong way of create lnk and the correct way. expandcollapse popup_Create_LNK_Shortcut('https://www.autoitscript.com/forum/', @DesktopDir) Func _Create_LNK_Shortcut($Url, $sFilePath) Local $LnkFilePath = $sFilePath ;Location & lnk name to saved to Local $Browser = @ProgramFilesDir & '\Internet Explorer\iexplore.exe' Local $Browser = @ProgramFilesDir & '\Google\Chrome\Application\chrome.exe' ;Part1 of Target: ;Local $Url = $sUrl ;Argument option Part 2 of Target for URL or options for EXE Local $Icon = $Browser ;lnk icon from exe Local $IconIndex = 0 Local $StartIn = @ProgramFilesDir & '\Google\Chrome\Application\' Local $StartIn = @ProgramFilesDir & '\Google\Chrome\Application\' Local $Comment = @YEAR&@MON&@MDAY&'_'&@HOUR&@MIN&@SEC&'.'&@MSEC ; wrong way to create *lnk FileCreateShortcut($Url, $LnkFilePath &'_wrong.lnk', $StartIn, "", $Comment, $Icon, '', $IconIndex, @SW_SHOWMAXIMIZED) ; correct way to create *lnk FileCreateShortcut($Browser, $LnkFilePath &'_correct.lnk', $StartIn, $Url, $Comment, $Icon, '', $IconIndex, @SW_SHOWMAXIMIZED) ; Retrieve details about the shortcut. Local $aDetails_wrong = FileGetShortcut($LnkFilePath &'_wrong.lnk') Local $aDetails_correct = FileGetShortcut($LnkFilePath &'_correct.lnk') If Not @error Then MsgBox($MB_SYSTEMMODAL, "Compare lnks", _ '___WRONG LNK___' & @CRLF & _ "Browser: " & $aDetails_wrong[0] & @CRLF & _ "StartIn: " & $aDetails_wrong[1] & @CRLF & _ "Url: " & $aDetails_wrong[2] & @CRLF & _ "Comment: " & $aDetails_wrong[3] & @CRLF & _ "Icon: " & $aDetails_wrong[4] & @CRLF & _ "Icon id: " & $aDetails_wrong[5] & @CRLF & _ "lnk state: " & $aDetails_wrong[6] & @CRLF & _ ''&@CRLF & _ '___CORRECT LNK___' & @CRLF & _ "Path: " & $aDetails_correct[0] & @CRLF & _ "StartIn: " & $aDetails_correct[1] & @CRLF & _ "Url: " & $aDetails_correct[2] & @CRLF & _ "Comment: " & $aDetails_correct[3] & @CRLF & _ "Icon: " & $aDetails_correct[4] & @CRLF & _ "Icon id: " & $aDetails_correct[5] & @CRLF & _ "lnk state: " & $aDetails_correct[6] & @CRLF) EndIf EndFunc Link to comment Share on other sites More sharing options...
zeenmakr Posted September 19, 2020 Author Share Posted September 19, 2020 tried reading *.lnk as text to then extract url with regexp but it only read in first letter 'L', any idea why Local $sFilePath = @DesktopDir &'\_wrong.lnk' Local $hFileOpen = FileOpen($sFilePath, $FO_BINARY) If $hFileOpen Then Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) MsgBox(0, 'lnk', BinaryToString($sFileRead, 4)) ;MsgBox(0, 'lnk in binary', $sFileRead) EndIf _wrong.zip Link to comment Share on other sites More sharing options...
jerem488 Posted September 19, 2020 Share Posted September 19, 2020 You have a solution here: https://www.autohotkey.com/docs/commands/FileCreateShortcut.htm Have a nice day Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
mLipok Posted September 19, 2020 Share Posted September 19, 2020 (edited) 6 minutes ago, jerem488 said: You have a solution here: https://www.autohotkey.com/docs/commands/FileCreateShortcut.htm It was not elegant, to say the least Edited September 19, 2020 by mLipok zeenmakr 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
jerem488 Posted September 19, 2020 Share Posted September 19, 2020 $Shortcut = @ScriptDir & '\MyShortcut.lnk' $Browser = @ProgramFilesDir & '\Internet Explorer\iexplore.exe' $Url = 'http://www.autoitscript.com/autoit3' $Icon = @SystemDir & '\shell32.dll' $IconIndex = 13 FileCreateShortcut($Browser, $Shortcut, '', $Url, '', $Icon, '', $IconIndex, @SW_SHOWMAXIMIZED) And if you want use another browser you can use the _WinAPI_FindExecutable() function to find your default browser. Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
zeenmakr Posted September 19, 2020 Author Share Posted September 19, 2020 4 minutes ago, jerem488 said: You have a solution here: https://www.autohotkey.com/docs/commands/FileCreateShortcut.htm appreciated the thought but i'm not looking for another way of creating shortcut. i've created lots of shortcuts but didn't realize that i format it incorrectly which resulted in shortcut can't be read by FileGetShortcut() to extract the url. Link to comment Share on other sites More sharing options...
zeenmakr Posted September 19, 2020 Author Share Posted September 19, 2020 3 minutes ago, jerem488 said: And if you want use another browser you can use the _WinAPI_FindExecutable() function to find your default browser. again, i'm trying to extract url from the shortcuts which i have already created incorrectly (: Link to comment Share on other sites More sharing options...
careca Posted September 19, 2020 Share Posted September 19, 2020 Are there many of them? Manual extraction of the path would be a way. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
zeenmakr Posted September 19, 2020 Author Share Posted September 19, 2020 31 minutes ago, careca said: Are there many of them? Manual extraction of the path would be a way. yea only a few thousands of these. as screenshot above demonstrated, manual extraction is not possible because field is disable plus is not the route i want to go through lol. could someone confirm why FileRead() can't read *.lnk as text but only able to read only the 1st letter 'L'. example shortcut '_wrong.lnk' file attached above. if shortcut could be read in as text show in notepad i could StringRegex() the url from that Link to comment Share on other sites More sharing options...
Danp2 Posted September 19, 2020 Share Posted September 19, 2020 Probably stops at the first null character it hits. Use FileOpen() to open the file in Binary mode. Then pass the file handle to FileRead. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
zeenmakr Posted September 19, 2020 Author Share Posted September 19, 2020 (edited) 7 minutes ago, Danp2 said: Probably stops at the first null character it hits. Use FileOpen() to open the file in Binary mode. Then pass the file handle to FileRead. if thats the case, how then to jump over it. tried that above Edited September 19, 2020 by zeenmakr Link to comment Share on other sites More sharing options...
Danp2 Posted September 19, 2020 Share Posted September 19, 2020 Have you tried supplying the optional count parameter? zeenmakr 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted September 19, 2020 Share Posted September 19, 2020 Try this : Local $hFileOpen = FileOpen($sFilePath & '_wrong.lnk', $FO_BINARY) If $hFileOpen Then Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) MsgBox ($MB_SYSTEMMODAL,"",BinaryToString(BinaryMid($sFileRead,107,80),2)) For $i = 1 to BinaryLen ($sFileRead) ConsoleWrite ($i & " = " & BinaryMid($sFileRead,$i,1) & @CRLF) Next EndIf zeenmakr 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
boom221 Posted September 19, 2020 Share Posted September 19, 2020 This works for me although it is not a failsafe approach. #include <Constants.au3> Local $filePath = @DesktopDir &'\_wrong.lnk' Local $fileHandle = FileOpen($filePath, $FO_ANSI) If Not @error Then Local $contents = StringRegExpReplace(FileRead($fileHandle), "\x00", "") Local $matches = StringRegExp($contents, "https?[\w:/.]*", $STR_REGEXPARRAYMATCH) msgbox($MB_SYSTEMMODAL, "", $matches[0]) FileClose($fileHandle) Else ConsoleWrite('Could not open file "' & $filePath & '".') Exit 1 EndIf zeenmakr 1 Link to comment Share on other sites More sharing options...
zeenmakr Posted September 19, 2020 Author Share Posted September 19, 2020 5 hours ago, Danp2 said: Have you tried supplying the optional count parameter? it looks like it fully read in the whole file but fails at BinaryToString(). suggested examples above by @boom221 to regex replace '\x00' and @Nine range out with BinaryMid() did the trick For $i = 1 to BinaryLen ($sFileRead) ConsoleWrite ($i & " = " & BinaryMid($sFileRead,$i,1) & @CRLF) Next @Nine very use for future testing approach, thanks @boom221 exactly what i'm looking for, thanks thanks again everyone, here is the alternative to FileGetShortcut() to only extract url from a corrupted or badly formatted shortcut Func _FileGetShortcutUrl($sFilePath) Local $sUrlMatch = '' ;Local $sFilePath = @DesktopDir &'\_wrong.lnk' Local $hFileOpen = FileOpen($sFilePath, $FO_ANSI) ;opt: $FO_UNICODE, $FO_UTF8 Local $iSizeCheck = FileGetSize($sFilePath) If $hFileOpen And $iSizeCheck Then Local $sFileRead = FileRead($hFileOpen) $sFileRead = StringRegExpReplace($sFileRead, "\x00", "") Local $regex_url = "https?[\w:/.]*" $sUrlMatch = StringRegExp($sFileRead, $regex_url, $STR_REGEXPARRAYMATCH)[0] MsgBox(0, @ScriptLineNumber&': lnk ', 'lnk: '&$sFileRead &@CRLF&@CRLF&'url: '&$sUrlMatch) Else MsgBox(0, @ScriptLineNumber&': lnk', 'Failed $hFileOpen or $iSizeCheck') EndIf FileClose($hFileOpen) Return $sUrlMatch EndFunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now