LNKEditorGUI - Windows Shortcut LNK Link Editor GUI

8 posts in this topic

#1 ·  Posted (edited)

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


@="\"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")

$Status = _GUICtrlStatusBar_Create($GUI)

GUICtrlCreateLabel("File:", 4, 6, 36, 24)
$inFilename = GUICtrlCreateInput("", 36, 4, 672, 24)

$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)

GUICtrlCreateLabel("Target Arguments", 4, 148, 172, 24)
$editTargetArgs = GUICtrlCreateEdit("", 4, 172, 792, 96, $ES_MULTILINE)

GUICtrlCreateLabel("Working Dir", 4, 288, 172, 24)
$inWorkingDir = GUICtrlCreateInput("", 4, 312, 792, 24)

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)

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)


#endregion - GUI

If $CmdLine[0] > 0 Then
    GUICtrlSetData($inFilename, $CmdLine[1])

While 1

Func StatusBarNotify($msg)
        _GUICtrlStatusBar_SetText($Status, $msg)
        _Timer_SetTimer($GUI, 5000, "_ClearStatusBar")

Func _ClearStatusBar($hWnd, $msg, $iIDTimer, $dwTime)
    #forceref $hWnd, $msg, $iIDTimer, $dwTime
    _GUICtrlStatusBar_SetText($Status, "")
    _Timer_KillTimer($hWnd, $iIDTimer)

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")
        $var = StringReplace($var, "|", @CRLF)
        GUICtrlSetData($inFilename, $var)

Func On_Drop_InFilename()
    If ( (@GUI_DropId = $inFilename) OR (@GUI_DropId = $inTargetEXE) ) Then
        GUICtrlSetData(@GUI_DropId, @GUI_DragFile)
    If ( (@GUI_DropId = $inFilename) AND (@GUI_DragFile <> "") ) Then

Func _btOpenFile()

    Local $filename = GUICtrlRead($inFilename)
    If $filename = "" Then
        ;$filename = GUICtrlRead($inFilename)
        StatusBarNotify("ERROR: Trying to open file but no file specified.")
        MsgBox(0,"ERROR","Trying to open file but no file specified.")

Func OpenFile($filename)
    Local $lnkArray = FileGetShortcut($filename)
    If Not @error Then
        StatusBarNotify("ERROR: Unable to open file.")
        MsgBox(0,"ERROR","Unable to open file, please check the file name.")
    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)
    StatusBarNotify("Successfully loaded file: " & $filename)

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.")

    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

    $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)
        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.")


Func _exit()

Edited by Jon
2 people like this

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)

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

Share this post

Link to post
Share on other sites

#3 ·  Posted


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


Share this post

Link to post
Share on other sites

#4 ·  Posted

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.

Share this post

Link to post
Share on other sites

#5 ·  Posted

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

Share this post

Link to post
Share on other sites

#6 ·  Posted

Thanks brow!

Share this post

Link to post
Share on other sites

#7 ·  Posted

Hey there.

I'm sorry to up an old thread.

Thanks for your tool.

I would like to know, is there a way (with this actual tool or in another way) to create a shortcut .lnk who could open 2 files ? For example 2 .html files, or 2 .jpeg files ?

I don't want to use a .bat to do that. I want to use a .lnk if it's possible.

Thanks a lot for your feedback and your advices.

Have a good day.



Share this post

Link to post
Share on other sites

#8 ·  Posted


Thanks for sharing.

Community news: Au3.3.14.2 Released  Please fix your own Signatures     ie.au3 UDF with AutoIt v3.3.14.x  for other useful stuff click the following button:

Last update: 2015-10-04
NEW: XMLWrapperEx.au3 - BETA 

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 * NEW: UDF for PDFCreator v1.x.x * XZip - UDF * TeamViewer API - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft Components *

My contribution to others projects: * _sql.au3 UDF  * SMTP Mailer UDF * _POP3_Ex.au3 UDF *  RTF Printer - UDF * 

Useful links: Forum etiquette * 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 * Best coding practices * 

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 * How to post code on the forum * UDF-Spec Questions

"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
naughty.gif  :ranting:, be  smile.png and       \\//_.

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