Log in

View Full Version : how to retrieve URLs from internet shortcuts?



asmja
08-06-2006, 03:33 PM
I have a form on which I have a text box "txtPath" which holds the path to a folder containing internet shortcuts. For example the Favorites folder. On the form I have a list box that has two columns and a command button.

What I need is that when I click on the command button, the list box would be filled with the internet shortcuts file names and URLs.

I've managed to get the file names but I haven't been able to get the URLs. I would appreciate any help

"Label6" is a label that hold the number of items the list box has

"txtextention" is a text box where I could set what file extention I want, in this case it woud be ".url"

here is the code I have behind the command button for now


Private Sub Command0_Click()
Dim FileName As String, i As Integer

'Clear the list box
For i = List1.ListCount - 1 To 0 Step -1
Me.List1.RemoveItem (i)
Next i

'add the list box columns headers
Me.List1.AddItem "Title; URL"

'get the file names of the internet shortcuts and
'add them to the list box
Path = txtPath & "\" & txtextention
FileName = Dir(Path)
Do While FileName <> ""
Me.List1.AddItem FileName
FileName = Dir
Loop

'set Label6 caption property to the number of items in the list box
'the minus 1 part is to account for the first item in the list box
'which would be the columns headers
Label6.Caption = Me.List1.ListCount - 1
End Sub

OBP
08-07-2006, 10:51 AM
Can I ask why you are using VBA to do what a Hyperlink Field does for you?

asmja
08-07-2006, 11:17 PM
I don't have hyperlinks, what I have are internet shortcuts and I am trying to get the URLs out of them.

Ideally, I would feed the URLs extracted from the internet shortcuts in the Favorites folder to a hyperlink field in a table, but the problem is how to get the URLs or addresses from the internet shortcuts.

Of course I could do this manually, by right clicking on each and every internet shortcut and choosing properties to copy the URL from there and then paste it wherever I want, but I've got a lot of internet shortcuts that it would be a hassle.

So I thought maybe this could be done programmatically.

Regards

stanl
08-08-2006, 06:29 AM
Question: are your referring to .lnk files or .url files, because that makes a difference?
Stan

asmja
08-08-2006, 07:18 AM
it's .url

just like the files you have under your favorites folder normally found at "C:\Documents and Settings\pc23\Favorites"

the "pc23" part would be different for you, it is the computer's name

stanl
08-08-2006, 08:27 AM
Although I do not think the problem is as complicated, this may help:
http://vbnet.mvps.org/index.html?code/internet/inetfavinfo.htm

Stan

asmja
08-08-2006, 01:24 PM
god.. I wish i understood that code or that there were some easier way to do this.. i could never really grasp that API Function stuff.. thanx a lot anyways stan.. appreciate the help

regards

stanl
08-08-2006, 04:59 PM
well you could always put a call out to a utility like this, the parse the resulting text file. Stan

http://windowsxp.mvps.org/ie/fav2txt.htm