-
Oct 7th, 2009, 09:38 PM
#1
Thread Starter
Fanatic Member
Create a shortcut using IWshRuntimeLibrary
Hello, if you were wondering how to create a shortcut for your application, here's a way to do it, using the IWshRuntimeLibrary .
First off, you need to add a reference to your application. You do this by right-clicking on the References menu item in the Solution Explorer. Select the Add Reference menu. From the Add Reference dialog, click the .COM tab and select the 'Windows Scripting Host Object Model' and click the 'Add' button.
After you have done that, just paste this code into your project, and voilá, you're done! .
vb.net Code:
Imports IWshRuntimeLibrary
Public Sub CreateShortCutOnDesktop()
Try
Dim ShortCut As IWshRuntimeLibrary.IWshShortcut
'Shortcuts have a .lnk extension...
ShortCut = CType(WshShell.CreateShortcut(My.Computer.FileSystem.SpecialDirectories.Desktop & _
"\MyAppName.lnk"), _
IWshRuntimeLibrary.IWshShortcut)
'Let's set the shortcut properties...
With ShortCut
.TargetPath = _
System.Reflection.Assembly.GetExecutingAssembly.Location()
.WindowStyle = 1
.Description = "A description for the shortcut.."
.WorkingDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
'This next line gets the first icon from the executing application..
.IconLocation = _
System.Reflection.Assembly.GetExecutingAssembly.Location() & _
", 0"
.Save() 'And save the shortcut...
End With
Catch ex As System.Exception
'Do something
End Try
End Sub
I hope you have found this easy and helpful.
Cheers .
Last edited by tassa; Oct 7th, 2009 at 09:42 PM.
-
Jan 28th, 2019, 05:57 AM
#2
Re: Create a shortcut using IWshRuntimeLibrary
Originally Posted by tassa
First off, you need to add a reference to your application. You do this by right-clicking on the References menu item in the Solution Explorer. Select the Add Reference menu. From the Add Reference dialog, click the .COM tab and select the 'Windows Scripting Host Object Model' and click the 'Add' button.
Thanks Tassa,
I wish I'd found that two days ago! I did find something similar but they're description must've lacked something because it made no difference.
Poppa.
Along with the sunshine there has to be a little rain sometime.
-
Mar 7th, 2023, 10:27 AM
#3
New Member
Re: Create a shortcut using IWshRuntimeLibrary
All,
I am pretty new to VB and I am using VB 2010 Express. I copied the above code, adjusted the variables to point to the right files and locations. I have added the reference to WSH Object models and imports Iwshruntimelibrary. I now have a compile error on line 8 of the above code. Specifically, with WshShell.CreateShortcut. The error is "Reference to a non-shared member requires an object reference. What does this mean and what am i doing wrong?
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|