[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Creating a ShellLinkObject

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

Independent Software Vendors: 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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

650 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