Jump to content

How can i create a .url shortcut with au3?


JmZ
 Share

Recommended Posts

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

:(

Link to comment
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

:(

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
Link to comment
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.

Link to comment
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!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...