Creating a ShellLinkObject

Hi all.

I'm trying to create a desktop shortcut from a VB program, using the Shell32 library. The code is:

    Dim sl As New Shell32.ShellLinkObject
    sl.Description = "System Folder"
    sl.Path = "C:\WINNT\System32"
    sl.Save "C:\Documents and Settings\CesarGon\Desktop\System.lnk"

But I get an error after the "New" line saying that it could not create the object. Should I use any specific mathod to create the ShellLinkObject?

Thanks,
CesarGon.
LVL 3
CesarGonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
WolfgangKoenigConnect With a Mentor Commented:
You must include in your vb project:
windows script host object model (Ver 1.0)

And then try this code:
__________________________________________________________


Private Sub Form_Load()
  Call CreateShortCut("C:\wok.lnk", "c:\hw.ini")
End Sub

Public Sub CreateShortCut(strShortcut_Path As String, strShortcut_Target As String)
  Dim Scriptshell As IWshShell_Class
  Set Scriptshell = New IWshShell_Class
  Set oShellLink = Scriptshell.CreateShortCut(strShortcut_Path)
  oShellLink.TargetPath = strShortcut_Target
  oShellLink.Save
End Sub



Hope that helps
WoK
0
 
rovermCommented:
Take a look here for a complete example:

http://www.thescarms.com/vbasic/VBFileOps.asp

D'Mzzl!
RoverM
0
 
CesarGonAuthor Commented:
Thanks, Wolfgang. We still don't know why the Shell32 library does not work, but your solution does the job.

Regards,
Cesar.
0
All Courses

From novice to tech pro — start learning today.