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.

Usage:

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.") 
    Return 
EndIf 
$shortcutOf = $CmdLine[1] 
If (Not FileExists($shortcutOf)) Then 
    MsgBox(16, "Error", "File/directory """ & $shortcutOf & """ do not exists") 
    Return 
EndIf 
$shortcutPath = @WorkingDir & "\" & "Shortcut of " & 
$shortcutOf & ".lnk" 
If ($CmdLine[0] = 2) Then 
    $shortcutPath = $CmdLine[2] 
    If (StringLower( StringRight($shortcutPath , 4)) <> ".lnk" ) Then 
        $shortcutPath = $shortcutPath & ".lnk" 
    EndIf 
EndIf 
$objShell = ObjCreate("Wscript.Shell") 
$shortcut = $objShell.CreateShortcut($shortcutPath) 
$shortcut.TargetPath = $shortcutOf 
$shortcut.WindowStyle = 1 
$shortcut.Save()

If you want to download script file click here

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

Powered by WordPress