?
Solved

Copy shortcuts with VB

Posted on 2006-06-01
5
Medium Priority
?
254 Views
Last Modified: 2010-04-30
I have code which copies files and folders using FSO, but does not copy actual shortcuts.  Instead, it copies the file that the shortcut points to.  How can I copy a shortcut with VB6?
0
Comment
Question by:CCIG2006
4 Comments
 
LVL 10

Expert Comment

by:harisrashid
ID: 16831375
hi,

FSO has a property that returns the path to the object. you need to save just the path (shortcut to the file) and not the FSO object it self. modify your code to store just the path returned by FSO.

Regards,

Haris
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 600 total points
ID: 16851329
y not?


Private Sub Command1_Click()
Dim FSO
     Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "C:\Shortcut to abc.lnk", "C:\Shortcut to abc1.lnk", false
End Sub

etc
0
 
LVL 35

Expert Comment

by:mvidas
ID: 16851734
CCIG,

You could always use windows scripting host:

 Dim wShell, wShortcut, wShortcut2
 Set wShell = CreateObject("wscript.shell")
 Set wShortcut = wShell.CreateShortcut("C:\YourShortcut.lnk") 'creates new shortcut if it doesnt exist, sets to existing if it does
 Set wShortcut2 = wShell.CreateShortcut("C:\Copy of YourShortcut.lnk") 'the copy
 With wShortcut2
  .Arguments = wShortcut.Arguments
  .Description = wShortcut.Description
  .Hotkey = wShortcut.Hotkey
  .IconLocation = wShortcut.IconLocation
  .TargetPath = wShortcut.TargetPath
  .WindowStyle = wShortcut.WindowStyle
  .WorkingDirectory = wShortcut.WorkingDirectory
  .Save
 End With
 MsgBox "'" & wShortcut2.FullName & "' target=" & wShortcut2.TargetPath
 Set wShell = Nothing
 Set wShortcut = Nothing
 Set wShortcut2 = Nothing

Matt
0
 

Author Comment

by:CCIG2006
ID: 16875427
This is part of the code I use to backup a file specified in the tmpData(j) variable.

        If tmpData(J) <> "" Then
            FSO.CreateFolder BackupPath & "\BF_" & J
            'FSO.CopyFile tmpData(J), BackupPath & "\BF_" & J & "\"
        End If

If I use the modified code below, it won't work.

        If tmpData(J) <> "" Then
            FSO.CreateFolder BackupPath & "\BF_" & J
            FSO.CopyFile tmpData(J) & ".lnk", BackupPath & "\BF_" & J & "\"
        End If

How can I have it differentiate between an actual file and a shortcut?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

864 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