?
Solved

Creating a ShellLinkObject

Posted on 2001-09-03
3
Medium Priority
?
1,129 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 800 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

765 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