Sign in to follow this  
Followers 0
JmZ

How can i create a .url shortcut with au3?

7 posts in this topic

How can i create a .url shortcut with au3?

FileCreateShortcut cannot help me with a .url shortcut.

Thanks

Share this post


Link to post
Share on other sites



Some COM code may help you.

; Example of creating a Url shortcut

If _WshUrlShortcut(@DesktopDir & '\AutoIt3.url', 'http://www.autoitscript.com/autoit3') Then
    MsgBox(0, @ScriptName, 'Url shortcut created')
EndIf

Exit

Func _WshUrlShortcut($sFilePath, $sUrl)
    ; Creates a Url shortcut
    Local $oUrlLink, $oWshShell
    $oWshShell = ObjCreate("WScript.Shell")
    If Not @error Then
        $oUrlLink = $oWshShell.CreateShortcut($sFilePath)
        If IsObj($oUrlLink) Then
            $oUrlLink.TargetPath = $sUrl
            $oUrlLink.Save
            If FileExists($sFilePath) Then
                Return True
            EndIf
        EndIf
    EndIf
EndFunc

:(

Share this post


Link to post
Share on other sites

can we just use functions in au3 without com?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Some COM code may help you.

; Example of creating a Url shortcut

If _WshUrlShortcut(@DesktopDir & '\AutoIt3.url', 'http://www.autoitscript.com/autoit3') Then
    MsgBox(0, @ScriptName, 'Url shortcut created')
EndIf

Exit

Func _WshUrlShortcut($sFilePath, $sUrl)
    ; Creates a Url shortcut
    Local $oUrlLink, $oWshShell
    $oWshShell = ObjCreate("WScript.Shell")
    If Not @error Then
        $oUrlLink = $oWshShell.CreateShortcut($sFilePath)
        If IsObj($oUrlLink) Then
            $oUrlLink.TargetPath = $sUrl
            $oUrlLink.Save
            If FileExists($sFilePath) Then
                Return True
            EndIf
        EndIf
    EndIf
EndFunc

:(

Thank you for the code!

But, how to set "icon" and "hotkey" for .url ?

I think maybe by this ?

$oUrlLink.IconLocation = $sIcon & "," & $iIndex
$oUrlLink.Hotkey = $sHotkey
Edited by JmZ

Share this post


Link to post
Share on other sites

Thank you for the code!

But, how to set "icon" and "hotkey" for .url ?

I think maybe by this ?

Seems as MSDN shows.

I searched as you did not like the idea of COM. So, the below is what I come up with.

_URLCreateShortcut('http://www.google.com/')

Func _URLCreateShortcut($url, $iconindex = 0, $iconfile = '')
    $h_write = FileOpen('test1.url', 33); unicode write
    If $h_write <> -1 Then
        FileWrite($h_write, _
                '[InternetShortcut]' & @CRLF & _
                'URL=' & $url & @CRLF & _
                'IconIndex=' & $iconindex & @CRLF & _
                'IconFile=' & $iconfile _
                )
        FileClose($h_write)
        Return True
    Else
        Return False
    EndIf
EndFunc

I did not find hotkey info, though more searching, perhaps local creation may reap results. Just view URL files by dropping on notepad to see contents.

Share this post


Link to post
Share on other sites

Seems as MSDN shows.

I searched as you did not like the idea of COM. So, the below is what I come up with.

_URLCreateShortcut('http://www.google.com/')

Func _URLCreateShortcut($url, $iconindex = 0, $iconfile = '')
    $h_write = FileOpen('test1.url', 33); unicode write
    If $h_write <> -1 Then
        FileWrite($h_write, _
                '[InternetShortcut]' & @CRLF & _
                'URL=' & $url & @CRLF & _
                'IconIndex=' & $iconindex & @CRLF & _
                'IconFile=' & $iconfile _
                )
        FileClose($h_write)
        Return True
    Else
        Return False
    EndIf
EndFunc

I did not find hotkey info, though more searching, perhaps local creation may reap results. Just view URL files by dropping on notepad to see contents.

Or just by IniWrite we can create .url easily...

Thank you very much for your help!

Share this post


Link to post
Share on other sites

This link may also interest you

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