JmZ Posted April 18, 2010 Posted April 18, 2010 How can i create a .url shortcut with au3? FileCreateShortcut cannot help me with a .url shortcut. Thanks
MHz Posted April 18, 2010 Posted April 18, 2010 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
JmZ Posted April 18, 2010 Author Posted April 18, 2010 (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 April 18, 2010 by JmZ
MHz Posted April 18, 2010 Posted April 18, 2010 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.
JmZ Posted April 18, 2010 Author Posted April 18, 2010 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now