Sign in to follow this  
Followers 0
bucky002

How Would I Create A Shortcut In Autoit?

9 posts in this topic

#1 ·  Posted (edited)

I want to know this because I made a little installer script.(Isn't completed yet) I would put the installer script inside one of my other scripts to install it, but how would I make it so it would create a shortcut on the desktop?

Here's my script

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("Installer", 293, 83,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_1 = GuiCtrlCreateInput(@ProgramFilesDir & "\AutoIt", 10, 10, 180, 20)
$Browse = GuiCtrlCreateButton("Browse", 210, 10, 60, 20)
$OK = GuiCtrlCreateButton("OK", 190, 50, 90, 30)
$Cancel = GuiCtrlCreateButton("Cancel", 90, 50, 90, 30)
$Checkbox_5 = GuiCtrlCreateCheckbox("Shortcut", 10, 60, 60, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Browse
         $file = FileSelectFolder("Browse", "", 1+2+4, @ProgramFilesDir)
         guictrlsetdata($Input_1, $file & "\AutoIt", "")
    Case $msg = $Cancel
        Exit
    Case $msg = $OK
         $dir = DirCreate(GUICtrlRead($Input_1))
         Exit
    Case Else
    ;;;
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---
Edited by bucky002

Share this post


Link to post
Share on other sites



Harder than I thought:

$pathToEXE = "C:\Windows\Notepad.exe"
$dirToShortcut = "C:\test\"
$shortcutName = "Shortcut to Notepad.lnk"

Func _CreateShortcut($pathToEXE, $dirToShortcut, $shortcutName)
    If  FileExists($pathToEXE) Then
        If DirCreate($dirToShortcut) Then
            $oWSHShell = ObjCreate("WScript.Shell")
            $oShortCutLink = $oWSHShell.CreateShortcut($dirToShortcut & "\" & $shortcutName)
            $oShortCutLink.TargetPath = $pathToEXE
            $oMyError = ObjEvent("AutoIt.Error", "ErrorFunc")
            $oShortCutLink.Save
        Else
            MsgBox(0,"","Could not create directory for shortcut.")
        EndIf
    Else
        MsgBox(0,"","File to make shortcut from does not exist.")
    EndIf
EndFunc

Func ErrorFunc()
    $hexErrorCode = Hex($oMyError.Number, 8)
    Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 
   SetError(1); something to check for when this function returns 
Endfunc

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

Harder than I thought:

CODE

$pathToEXE = "C:\Windows\Notepad.exe"

$dirToShortcut = "C:\test\"

$shortcutName = "Shortcut to Notepad.lnk"

Func _CreateShortcut($pathToEXE, $dirToShortcut, $shortcutName)

If FileExists($pathToEXE) Then

If DirCreate($dirToShortcut) Then

$oWSHShell = ObjCreate("WScript.Shell")

$oShortCutLink = $oWSHShell.CreateShortcut($dirToShortcut & "\" & $shortcutName)

$oShortCutLink.TargetPath = $pathToEXE

$oMyError = ObjEvent("AutoIt.Error", "ErrorFunc")

$oShortCutLink.Save

Else

MsgBox(0,"","Could not create directory for shortcut.")

EndIf

Else

MsgBox(0,"","File to make shortcut from does not exist.")

EndIf

EndFunc

Func ErrorFunc()

$hexErrorCode = Hex($oMyError.Number, 8)

Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _

"Number is: " & $HexNumber & @CRLF & _

"Windescription is: " & $oMyError.windescription )

SetError(1); something to check for when this function returns

Endfunc

Easier than I thought: FileCreateShortcut() in Beta. :think:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

U took the words out of my mouth


My Scripts:Radioblog Club Music DownloaderOther stuff:Fun movieIm serious read the help file it helps :PFight 'Till you drop. Never stop, You Cant give up. Til you reach the top Fight! you’re the best in town Fight!

Share this post


Link to post
Share on other sites

Bah! there goes another 15 mins. of my life.

If you don't mind wasting another minute or two...

What the heck is that in your user picture? :think:

It looks the black spy from 'Spy Vs Spy' in Mad Magazine, having a heart attack. :(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hah, you're the first that asked.. it's been my general forum picture for awhile now. My sig in another forum was "Chili Cheese Burritos make me smile..." and I needed an avatar pic, so I did a google image search for "Chili Cheese Burritos" and behold. I had to have it. It's interesting you asked me where it's from, though, because I just re-searched for it and it turns out it's from Columbia University's school paper. Who knew? Without further ado...

Chili Cheese Burritos make me smile...

P.S.: Sorry for OT


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

Thanks for the help. :think:

Share this post


Link to post
Share on other sites

im guessing its a chili cheese burrito tied up and a guy smiling cuz he got one?

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
Sign in to follow this  
Followers 0