Modify *.lnk File?

J

Joe Duchtel

Hello -

I'm trying to put together a little VB .NET (1.1 in VS 2003)
application that lets me substitute the path in the Target: and Start
in: fields of *.lnk files. Is there any way to do that?

I saw examples of VBScripts using WSH but I would like to do it in
VB .NET. Is support for *.lnk built into .NET?

Thanks,
Joe
 
K

kimiraikkonen

Hello -

I'm trying to put together a little VB .NET (1.1 in VS 2003)
application that lets me substitute the path in the Target: and Start
in: fields of *.lnk files. Is there any way to do that?

I saw examples of VBScripts using WSH but I would like to do it in
VB .NET. Is support for *.lnk built into .NET?

Thanks,
Joe

Hi Joe,
I couldn't find a native way for modifying shortcuts, but you can do
by referencing "Windows script host object model" from COM tab.

And a sample code for you:
Dim shortCut As IWshRuntimeLibrary.IWshShortcut
Dim shortCut As IWshRuntimeLibrary.IWshShortcut
' Set path of shorcut (.lnk) file
shortCut = CType((New
IWshRuntimeLibrary.WshShell).CreateShortcut("shortcut.lnk"), _
IWshRuntimeLibrary.IWshShortcut)
shortCut.TargetPath = "target_path_here"
shortCut.Description = "description_here"
' Save
shortCut.Save()

..and hoping that is useful for who are looking for similar help :)

Thanks,

Onur Güzel
 
J

Joe Duchtel

Hello -

Perfect ... works like a charm! The only question I have is whether
it is really necessary to set the Copy Local to True for the
Interop.IWshRuntimeLibrary.dll. It does not seem to find this *.dll
if I set the Copy Local to False. I just don't like having to
distribute extra files with an *.exe.

Thanks a lot!
Joe
 
K

kimiraikkonen

Hello -

Perfect ... works like a charm! The only question I have is whether
it is really necessary to set the Copy Local to True for the
Interop.IWshRuntimeLibrary.dll. It does not seem to find this *.dll
if I set the Copy Local to False. I just don't like having to
distribute extra files with an *.exe.

Thanks a lot!
Joe

Glad it worked! I recommend you to also have this library in your
application folder, think that, what if the library is not present on
target machine? However, after you build your project the library is
copied to your application's bin\debug folder anyway, then you're
ready to deploy your application.

Thanks,

Onur Güzel
 
K

Kevin S Gallagher

Why not treat it as an INI file since it's plain text instead of using
classes like WshShell
 
H

Herfried K. Wagner [MVP]

Kevin S Gallagher said:
Why not treat it as an INI file since it's plain text instead of using
classes like WshShell

I think you are referring to URL files.

The shell link format is a "binary" format.
 
B

Brianhub

I am using this technique to modify an existing shortcut too. It seems to be
working well except for some inconsistencies in how the tooltip is displayed.
We wanted to tool tip to up as two lines like the Internet Explorer shortcut
with the Name of the shortcut in the first line and the description in the
second line. The IE shortcut only has the description in the comment field.
When I create our shortcut this way it only shows the description as a single
line tooltip. However, every once in a while it will display correctly as a
two line tooltip. If I modify the comment field to display the name and a new
line character and the description it displays correctly most of the time.
However, in this case sometimes it displays a three line tooltip with the
name displayed twice.

There must be a way to reliably display the tooltip correctly because to IE
shortcut always seems to work. Does anyone know of a way to fix this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top