Jump to content


LNKEditorGUI - Windows Shortcut LNK Link Editor GUI

lnk shortcut

  • Please log in to reply
4 replies to this topic

#1 robertcollier4



  • Active Members
  • Pip
  • 55 posts

Posted 13 June 2013 - 10:58 PM

Scenario: Editing .lnk shortcuts with the Windows dialog is very frustrating due to the small input boxes and non-resizable small dialog window. Very often you need to create a link with a long path and many arguments which becomes hard to see and make edits.
Solution: LNKEditorGUI is a resizable and easy to use creator and editor of LNK Windows Shortcut files. This GUI uses built-in AutoIt functions FileGetShortcut() and FileCreateShortcut() to read and write .lnk files. A nice and big (and resizable) GUI is presented with which the user can easily edit and create LNK shortcuts with. A command line argument is accepted and the GUI will automatically open the first file passed to it as an argument allowing for easy association on the right-click menu (see .lnk file right-click context menu registry association example below).
Attached File  LNKEditorGUI.zip   1.95KB   2638 downloads
Reg Script Use a Registry Script such as following to create a right-click menu entry for LnkEditorGUI for .lnk files.

Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\lnkfile\shell\LNKEditorGUI] @="LNK&EditorGUI" [HKEY_CLASSES_ROOT\lnkfile\shell\LNKEditorGUI\command] @="\"C:\\Program Files\\LNKEditorGUI.exe\" \"%1\""

LNKEditorGUI.au3 Code:

#include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <ComboConstants.au3> #include <GuiStatusBar.au3> #include <Timers.au3> #include <Array.au3> Opt("GUIOnEventMode", 1) Global Const $CmbWinstateNorm = @SW_SHOWNORMAL & " - Normal Window" Global Const $CmbWinstateMin = @SW_SHOWMINNOACTIVE & " - Minimized" Global Const $CmbWinstateMax = @SW_SHOWMAXIMIZED & " - Maximized" #region - GUI $GUI = GUICreate("LNKEditorGUI - Windows Shortcut LNK File Editor", 800, 640, -1, -1, BitOr($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX ), $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_CLOSE, '_exit') GUISetOnEvent($GUI_EVENT_DROPPED, "On_Drop_InFilename") GUISetFont(10) $Status = _GUICtrlStatusBar_Create($GUI) GUICtrlCreateLabel("File:", 4, 6, 36, 24) $inFilename = GUICtrlCreateInput("", 36, 4, 672, 24) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $btBrowseForFile = GUICtrlCreateButton("Browse...", 712, 4, 84, 24) GUICtrlSetOnEvent(-1, '_btBrowseForFile') $btOpenFile = GUICtrlCreateButton("Load LNK File", 20, 32, 370, 28) GUICtrlSetOnEvent(-1, '_btOpenFile') GUICtrlSetResizing($btOpenFile, $GUI_DOCKLEFT) $btSaveFile = GUICtrlCreateButton("Save LNK File", 410, 34, 370, 28) GUICtrlSetOnEvent(-1, '_btSaveFile') GUICtrlSetResizing($btSaveFile, $GUI_DOCKRIGHT) GUICtrlCreateLabel("Target EXE", 4, 80, 172, 24) $inTargetEXE = GUICtrlCreateInput("", 4, 104, 792, 24) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("Target Arguments", 4, 148, 172, 24) $editTargetArgs = GUICtrlCreateEdit("", 4, 172, 792, 96, $ES_MULTILINE) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("Working Dir", 4, 288, 172, 24) $inWorkingDir = GUICtrlCreateInput("", 4, 312, 792, 24) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("Window State", 4, 356, 172, 24) $cmbWindowState = GUICtrlCreateCombo("", 4, 380, 792, 24, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, $CmbWinstateNorm & "|" & $CmbWinstateMin & "|" & $CmbWinstateMax, $CmbWinstateNorm) ; add other item snd set a new default GUICtrlCreateLabel("Icon File", 4, 424, 172, 24) $inIconFile = GUICtrlCreateInput("", 4, 448, 650, 24) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlCreateLabel("Icon Index", 680, 424, 172, 24) $inIconIndex = GUICtrlCreateInput("", 674, 448, 112, 24) GUICtrlCreateLabel("Comment", 4, 492, 172, 24) $editComment = GUICtrlCreateEdit("", 4, 516, 792, 96, $ES_MULTILINE) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetState(@SW_SHOW, $GUI) #endregion - GUI If $CmdLine[0] > 0 Then     ;MsgBox(0,0,$CmdLine[1])     GUICtrlSetData($inFilename, $CmdLine[1])     _btOpenFile() EndIf While 1     Sleep(100) WEnd ;--------------------------------------------------------------- Func StatusBarNotify($msg)         _GUICtrlStatusBar_SetText($Status, $msg)         _Timer_SetTimer($GUI, 5000, "_ClearStatusBar") EndFunc ;--------------------------------------------------------------- Func _ClearStatusBar($hWnd, $msg, $iIDTimer, $dwTime)     #forceref $hWnd, $msg, $iIDTimer, $dwTime     _GUICtrlStatusBar_SetText($Status, "")     _Timer_KillTimer($hWnd, $iIDTimer) EndFunc ;--------------------------------------------------------------- Func _btBrowseForFile()     Local $var = FileSaveDialog("Choose a LNK File Name", "D:\", "LNK Shortcuts (*.lnk)", 2) ; option 2 = dialog remains until valid path/file selected     If @error Then         ;MsgBox(4096, "", "No File(s) chosen")     Else         $var = StringReplace($var, "|", @CRLF)         GUICtrlSetData($inFilename, $var)     EndIf EndFunc ;--------------------------------------------------------------- Func On_Drop_InFilename()     If ( (@GUI_DropId = $inFilename) OR (@GUI_DropId = $inTargetEXE) ) Then         GUICtrlSetData(@GUI_DropId, @GUI_DragFile)     EndIf     If ( (@GUI_DropId = $inFilename) AND (@GUI_DragFile <> "") ) Then         OpenFile(@GUI_DragFile)     EndIf EndFunc ;--------------------------------------------------------------- Func _btOpenFile()     Local $filename = GUICtrlRead($inFilename)     If $filename = "" Then         ;_btBrowseForFile()         ;$filename = GUICtrlRead($inFilename)         StatusBarNotify("ERROR: Trying to open file but no file specified.")         MsgBox(0,"ERROR","Trying to open file but no file specified.")     Else         OpenFile($filename)     EndIf EndFunc ;--------------------------------------------------------------- Func OpenFile($filename)     Local $lnkArray = FileGetShortcut($filename)     If Not @error Then         ;_ArrayDisplay($lnkArray)     Else         StatusBarNotify("ERROR: Unable to open file.")         MsgBox(0,"ERROR","Unable to open file, please check the file name.")         Return     EndIf     GUICtrlSetData($inTargetEXE, $lnkArray[0])     GUICtrlSetData($editTargetArgs, $lnkArray[2])     GUICtrlSetData($inWorkingDir, $lnkArray[1])     GUICtrlSetData($inIconFile, $lnkArray[4])     GUICtrlSetData($inIconIndex, $lnkArray[5])     GUICtrlSetData($editComment, $lnkArray[3])     If($lnkArray[6] = @SW_SHOWNORMAL) Then         GUICtrlSetData($cmbWindowState, $CmbWinstateNorm)     ElseIf($lnkArray[6] = @SW_SHOWMINNOACTIVE) Then         GUICtrlSetData($cmbWindowState, $CmbWinstateMin)     ElseIf($lnkArray[6] = @SW_SHOWMAXIMIZED) Then         GUICtrlSetData($cmbWindowState, $CmbWinstateMax)     EndIf     StatusBarNotify("Successfully loaded file: " & $filename) EndFunc ;--------------------------------------------------------------- Func _btSaveFile()     $filename = GUICtrlRead($inFilename)     If $filename = "" Then         StatusBarNotify("ERROR: Trying to save but no file name specified.")         MsgBox(0,"ERROR","Trying to save but no file name specified.")         Return     EndIf     Local $WinStateToWrite     Switch GuiCtrlRead($cmbWindowState)         Case $CmbWinstateNorm             $WinStateToWrite = @SW_SHOWNORMAL         Case $CmbWinstateMin             $WinStateToWrite = @SW_SHOWMINNOACTIVE         Case $CmbWinstateMax             $WinStateToWrite = @SW_SHOWMAXIMIZED         Case Else             $WinStateToWrite = @SW_SHOWNORMAL     EndSwitch     $saveResult = FileCreateShortcut(GuiCtrlRead($inTargetEXE), $filename, GuiCtrlRead($inWorkingDir), GuiCtrlRead($editTargetArgs), GuiCtrlRead($editComment), GuiCtrlRead($inIconFile), "", GuiCtrlRead($inIconIndex), $WinStateToWrite)     If($saveResult) Then         StatusBarNotify("Successfully saved file to: " & $filename)     Else         StatusBarNotify("ERROR: Unable to save file, please check the file name and values.")         MsgBox(0,"ERROR","Unable to save file, please check the file name and values.")         EndIf EndFunc ;--------------------------------------------------------------- Func _exit()     Exit EndFunc ;---------------------------------------------------------------

Edited by Jon, 27 November 2013 - 03:59 PM.

  • jaberwacky likes this

#2 robertcollier4



  • Active Members
  • Pip
  • 55 posts

Posted 14 June 2013 - 12:03 PM

FYI - this tool is very good with and was inspired by my use of hstart. Highly recommended:

For example, with hstart.exe you can launch multiple BAT files or EXE commands to run in parallel and without showing console with the /NOCONSOLE command, for example, this launches 3 batch files with multiple arguments (and without ever showing any windows):

hstart.exe /NOCONSOLE ""C:\program files\folderblue\processblue.bat" "blue arg 1" "blue arg 2" "blue arg 3"" ""C:\program files\folderred\processred.bat" "red arg 1" "red arg 2" "red arg 3"" ""C:\program files\foldergreen\processgreen.bat" "green arg 1" "green arg 2" "green arg 3""

Notice how this lnk file would get very unwieldy for the Windows edit properties dialog but LNKEditorGUI would handle it with ease.

Edited by robertcollier4, 14 June 2013 - 12:04 PM.

#3 trybowski



  • New Members
  • 1 posts

Posted 25 July 2013 - 10:48 AM


Nice one!


It's understandable, that this editor only allows editing certain, limited range of LNK properties. The problem is that it removes all other properties form a LNK file. I'm especially focused on console properties, which are removed altogether.


It's easily reproducible: create an LNK file in Windows, set some console properties (custom font, custom colors). Then open the LNK file in LNKEditorGUI and save it. The console properties are now gone, you can easily see this by editing the LNK again in Windows.


Could this be fixed?


Also, could the editor be extended to allow edititng of console properties?


Rgds, KT



#4 Ascend4nt



  • Active Members
  • PipPipPipPipPipPip
  • 1,371 posts

Posted 25 July 2013 - 11:26 AM

trybowski, those settings aren't saved in the shortcut (.LNK) file itself.


Look in the registry at this key:




That key gets updated with each change you make to a shortcut.  Older versions of Windows that emulated DOS used a .PIF file to save extra information.

#5 JonnyHotchkiss



  • New Members
  • 1 posts

Posted 13 March 2015 - 11:43 PM

Hi, nice app! So, this can be used to create  .lnks via command, ie a context menu entry?


I don't like having to right-click on the Favorites (%sysdrive%\users\%username%\LINKS) icon / whitespace in Explorer's navigation pane...


I've experimented with junctions etc, and it works... but not as well as a DeskLink file would

 [like the Desktop (create shortcut).DeskLink Desklink in Sendto]


Creating .DeskLinks is a bit out of my league... could this be added in?!!?!


Thanks :D

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users