Solved

Creating a ShellLinkObject

Posted on 2001-09-03
3
1,109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 70
Export Data to Different .csv Files 26 121
VBA: Insert New column with specific format type 12 52
Remove Exif Orientation before adding image to db 9 38
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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

740 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