July 23, 2008

Creating a windows shortcut using AutoIt

Filed under: autoIt,robo coding Himanshu @ 6:07 am

AutoIt library do have function to create windows shortcut, FileCreateShortcut. AutoIt script to create new shortcut of specified target in specified file/folder. Once compiled and created executable, use it in following way.


shortCut.exe  []

First parameter is required and should be path of file/folder for which to create shortcut

Second parameter is optional and if specified, should be full existing path including shortcut file name. If not specified shortcut will be created in the folder from where executable is run.

If ($CmdLine[0] < 1) Then
    MsgBox(16, "Error", "Insufficent parameters. In first parameter, specify for which file, shortcut should be created.") 
$shortcutOf = $CmdLine[1] 
If (Not FileExists($shortcutOf)) Then 
    MsgBox(16, "Error", "File/directory """ & $shortcutOf & """ do not exists") 
$shortcutPath = @WorkingDir & "\" & "Shortcut of " & 
$shortcutOf & ".lnk" 
If ($CmdLine[0] = 2) Then 
    $shortcutPath = $CmdLine[2] 
    If (StringLower( StringRight($shortcutPath , 4)) <> ".lnk" ) Then 
        $shortcutPath = $shortcutPath & ".lnk" 
$objShell = ObjCreate("Wscript.Shell") 
$shortcut = $objShell.CreateShortcut($shortcutPath) 
$shortcut.TargetPath = $shortcutOf 
$shortcut.WindowStyle = 1 

If you want to download script file click here

Let me know if you need any further help in it.


  1. Hi,
    I want to create a autoit script which will open winmerge . compare Two folders and generate a HTML report . win merge is a freeware software for the file and folder comparission. i am completely new to Auto it .
    Help is appricicated.

    Comment by ratikant — May 11, 2009 @ 11:39 pm

  2. hi there

    we are currently migrating from Windows 2000 to Windows XP. As part of our install script we copy a shortcut .lnk file from the server to the user’s pc. This link file is already set up with the appropriate target and more importantly A SHORTCUT KEY combination to launch the link. ie. Ctrl + F9. However for some reason this shortcut key does not work on XP but it worked on 2000 fine. You have to physically go into the shortcut and reassign the Shortcut key then all works fine. The question i have is how can we fix this. Is this something stored in the registry that we can poke to assign the Shortcut key again. If not then we do use AutoIt so maybe we can build something in that to assign the shortcut key on the installation.

    If you can assist then we would be most grateful. Thanks in advance, Simon

    Comment by Simon Hodgkinson — June 29, 2009 @ 4:18 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress