with VB create a shortcut to a web site? 
Author Message
 with VB create a shortcut to a web site?

Hi, has anyone ever created a shortcut to an internet site and save it in
the 'favorites' directory using VB?
If so an example would help.

Thanks
Mike Pollett




Sat, 23 Jun 2001 03:00:00 GMT  
 with VB create a shortcut to a web site?
Hi Mike,

Place this in a form:

Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Boolean
End Type

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As
Long
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA"
(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal
samDesired As Long, ByRef phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32" Alias
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal
lpReserved As Long, ByRef lpType As Long, ByVal szData As String, ByRef
lpcbData As Long) As Long
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ As Long = 1
Private Const ERROR_SUCCESS = 0&

Public Sub CreateInetShortcut(ByVal Title As String, ByVal URL As String)

Dim hKey As Long
Dim strFolder As String, szBuffer As String, lngBuffLen As Long
Dim lngReturn As Long
Dim hFile As Integer
Dim strFileName As String
Dim strContent As String

On Error Resume Next

Call RegOpenKeyEx(HKEY_CURRENT_USER,
"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", 0, 0,
hKey)

'// Open the key
If hKey = 0 Then Exit Sub

'//Create a buffer
szBuffer = String$(255, Chr$(0))

lngBuffLen = Len(szBuffer)

'//Query the value
lngReturn = RegQueryValueEx(hKey, "Favorites", 0, REG_SZ, szBuffer, lngBuffLen)

Call RegCloseKey(hKey)

'//Return obtained value
If lngReturn <> ERROR_SUCCESS Then Exit Sub

strFolder = Left$(szBuffer, lngBuffLen - 1)

hFile = FreeFile()

strFileName = strFolder & "\" & Title & ".URL"

Open strFileName For Binary Access Read Write Lock Read Write As hFile

strContent = strContent & "[InternetShortcut]" & vbCrLf
strContent = strContent & "URL=" & URL & vbCrLf

Put hFile, , strContent

Close hFile

End Sub

Then, for example, call:  CreateInetShortcut "The VB Box",
"http://members.xoom.com/kprobst/"
[shameless self-plug <g> ]

Of course, of you want to place the shortcut in a subfolder you'll have to
specify the path. You could do that by specifying the relative path in the
Title argument:

CreateInetShortcut "Great Links\The VB Box", "http://members.xoom.com/kprobst/"
[another shameless self-plug <bg> ]

As long as the folder exists under Favorites, this will work, because the VB
Open statement creates files, but not folders.

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Please post/reply to the newsgroup(s) so
that everyone can benefit from the discussion.

Regards,

Klaus H. Probst, MCP


       ICQ: 22454937
      The VB Box: http://members.xoom.com/kprobst/
~~~~~~~~~~~~~~~~~~~~~~~~~~~



Quote:
> Hi, has anyone ever created a shortcut to an internet site and save it in
> the 'favorites' directory using VB?
> If so an example would help.

> Thanks
> Mike Pollett





Sat, 23 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. with VB create a shortcut to a web site?

2. with VB create a shortcut to a web site?

3. Create web site and vdirs with VB.NET

4. Use ASP or VB component to create a virtual web site for IIS

5. Create a Web Folder shortcut

6. Create web shortcut on user's desktop

7. Creating Polygon Forms - Lost Web Site!

8. FYI - New Web Site Security Issue - Cross Site Scripting Vulnerability

9. Site Maps - for web site

10. Best site for freelancer work (PHP, Web site, java, oracle sql, php, data entry)

11. Sending Web Visitors to a backup web site if main one is down

12. Detecting bad web site in web browser control

 

 
Powered by phpBB® Forum Software