The .NET way to create shortcuts (ShellLink)

Posted Sat, Sep 18 2004 1:19 by bill

In a recent blog entry, Duncan pointed out a way to create a shell link (shortcut) using windows scripting host.  If you ask me though, that is a pretty chunky approach as it means you have a COM wrapper for WSH, and WSH itself is just wrappers for the calls to the underlying system API.  So, it’s layer upon layer upon layer.  That’s good if it’s a toblerone, but not so good for efficient code.

A much cooler approach is to use the very nice .NET wrapper classes Mattias Sjögren provided a few years back.   The wrappers and samples are written in both VB.NET and C#.

And the even better news is that in Whidbey, the COMImport attribute bug has been fixed so the work-arounds Mattias used in VB.NET such as Activator.CreateInstance won’t be needed.

In any case, it’s great code, grab it today (oh and avoid using WSH for this)

Filed under: ,

Comments

# re: The .NET way to create shortcuts (ShellLink)

Thursday, October 07, 2004 1:16 PM by bill

Bill, please be mindful that everything that is not Win32 API is essentially a wrapper; including .NET CLR (probably until the release of Longhorn). I can't see that much overhead in the interaction between Scripting runtime and COM objects instantiated during the execution of a script.
Besides, do you really need that much efficiency for creating just a shortcut? WSH is widely available on almost all default Windows installation, while .NET is not. So that's definitely a big plus.

Don't you think it's really that efficient to waste hundreds of megs for .NET framework installation, when all you need is just automating the creation of a bloody shorcut? Read Brendon Chase editorial in Builder AU's October 2004 edition, you probably need to renew your state of mind and not get too carried away by only a specific tool just because you think you know it best. ;) Good luck, Bill!

# re: The .NET way to create shortcuts (ShellLink)

Thursday, October 14, 2004 12:16 PM by bill

You mean I have to download 22MB of .NET framework just to create a wrapper for a shortcut ? Hmmmmm .. sounds justifying.

.NET is good, but it's not the solution for every problems.

# re: The .NET way to create shortcuts (ShellLink)

Thursday, June 09, 2005 2:01 AM by bill

22KB, not 22MB.

# re: The .NET way to create shortcuts (ShellLink)

Friday, December 02, 2005 10:47 PM by bill

its not working when i run it using VS.NET 2003...