Solved

Creating a ShellLinkObject

Posted on 2001-09-03
3
1,098 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:CesarGon
3 Comments
 
LVL 4

Accepted Solution

by:
WolfgangKoenig earned 200 total points
ID: 6450636
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
 
LVL 12

Expert Comment

by:roverm
ID: 6450668
Take a look here for a complete example:

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

D'Mzzl!
RoverM
0
 
LVL 3

Author Comment

by:CesarGon
ID: 6450915
Thanks, Wolfgang. We still don't know why the Shell32 library does not work, but your solution does the job.

Regards,
Cesar.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now