Tuesday, August 4, 2009

Create and internet shortcut using vb6

Maybe you want to create a shortcut in order to facilitate an internet connection you are connected to the internet. Here is a simple example to create a shortcut to the internet using VB6. First, create a new module, and after that paste the following code:

Public Const NOERROR = 0
Public Const CSIDL_FAVORITES = &H6
Public Const CSIDL_DESKTOPDIRECTORY = &H10

Private Type SHITEMID
cb As Long
abID As Byte
End Type

Private Type ITEMIDLIST
mkid As SHITEMID
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll"_
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long,_
ByVal pszPath As String) As Long

Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long,_
ByVal nFolder As Long,_
pidl As ITEMIDLIST) As Long

Private Function GetSpecialPath(CSIDL As Long) As String

Dim r As Long
Dim path As String
Dim IDL As ITEMIDLIST

'fill the idl structure with the specified folder item
r = SHGetSpecialFolderLocation(Me.hwnd, CSIDL, IDL)

If r = NOERROR Then
path$ = Space$(512)
r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal path$)
GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1)
Exit Function
End If

GetSpecialPath = ""

End Function

Public Sub CreateShortcut()

Dim URLpath As String
Dim CSIDLpath As String
Dim nameofLink As String
Dim ff As Integer
URLpath = "http://vb6stuff.blogspot.com"
CSIDLpath = GetSpecialPath(CSIDL_FAVORITES) & ""
nameofLink = "VB6 Stuff.url"

ff = FreeFile

Open CSIDLpath & nameofLink For Output As #ff
Print #ff, "[InternetShortcut]"
Print #ff, "URL=" & URLpath
Close #ff

End Sub


No comments:

Post a Comment