I'm Looking For A Control . . .

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

.. . . that allows me to drag and drop shortcuts on to a form. It should be
able to launch the application when the icon is double-clicked. Is there
such a control in Visual Studio 2005? Are there any third-party controls
that have this functionality?
 
Hi,

You do not need a control. All you need is code like this:

System.Diagnostics.Process.Start("C:\file2run") 'use the actual path

Naturally, you could attach this code to the click event for an image or
command button (for example).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Thank you for the response. On your suggestion, I've tried out the "Start"
method. It looks like this is used to directly run applications or run a
document with a "File Type" association.

I was really hoping to be able to directly run a shortcut. For example, I
might want to create a shortcut to "System" on "Control Panel" or a printer
and then start that shortcut. When I tried the "Start" method out on a
shortcut it said "No application is associated with the specified file for
this operation".

Is there a similar method that works on shortcuts? Is it possible to pull
the "Target" and icon information out of a shortcut and then use "Start" to
run it? Will this also work with special shortcuts like system objects
(printers and network connections, etc.) or just documents and programs?
 
I think I’m getting closer to finding what I need, but I’m not there yet.

I found this article on Shell Links:
http://msdn2.microsoft.com/en-us/library/aa969393.aspx. Basically, it says
that what I’m trying to do is “resolve†the shell link.

Searching on “resolve shell link†led me
http://msdn2.microsoft.com/en-us/library/ms630340.aspx which contains a
Visual Basic example of the resolution process. It looks like it was written
for VB 5.0 so I’ve tried to update it to a .Net version. This is what I came
up with.

Imports Shell32
Imports Shell32.ShellSpecialFolderConstants

Module Module1

Public Sub Main()

ResolveShellLink("C:\Documents and Settings\All Users\" & _
"Start Menu\Programs\Accessories", _
"Calculator.lnk")
ResolveShellLink ("C:\Documents and Settings\All Users\Desktop", _
"System.lnk")

End Sub


Private Function ResolveShellLink(PathName As String, _
ShortcutName As String) As Boolean

Dim objShell As Shell = New Shell()
If objShell Is Nothing Then Return False

Dim objFolder As Folder = objShell.NameSpace(PathName)
If objFolder Is Nothing Then Return False

Dim objFolderItem As FolderItem = objFolder.ParseName(ShortcutName)
If objFolderItem Is Nothing Then Return False

Dim objShellLink As ShellLinkObject = _
CType(objFolderItem.GetLink(), ShellLinkObject)
If objShellLink Is Nothing Then Return False

objShellLink.Resolve(1)

Return True

End Function

End Module

After adding a reference to COM module “Microsoft Shell Controls And
Automation†I was able to compile and run this code without any errors.
Unfortunately, it didn’t run “Calculator†or the shortcut to “System†that I
had placed on my desktop. What needs to be done to get this to run the
applications in the shortcuts?
 
Back
Top