Create URL Shortcut with Invoke Code

Hi guys,

I want to automatically create a .url shortcut to a website in a specified folder.
Instead of using the Windows UI (right-click in a folder → New → Shortcut) I want to create the shortcut with an Invoke Code activity (Other suggestions are welcome).

How do I do that?

I tried with different code snippets I found online, like this one:

Dim szName As String = "Demo Shortcut url"
Dim szUrl As String = "www.codeproject.com"
Dim szTarget As String = Target(PathTo.Desktop)
Dim szCreateDirForStartMenu As String = "Project Demo"
AddUrlShortcut(szName, szUrl, szTarget, szCreateDirForStartMenu)

But I couldn’t make it work, even without any variables or arguments.
Do I need to do any Imports first? If so, how?

Thanks in advance,
Lukas

that part is a function that you cant have in there… you will need to extract what is in that function and put directly in there…

Hey buddy, thanks for the reply!

It was really difficult and confusing with VBNet. I had to use WshShellClass and IWshRuntimeLibrary.IWshShortcut and just kept getting one error after the other.

I managed to achieve my objective with very simple CSharp code though:
(with arguments directory, name and url)

{
using (StreamWriter writer = new StreamWriter(directory + "\\" + name))
{
 writer.WriteLine("[InternetShortcut]");
 writer.WriteLine("URL=" + url);
 writer.Flush();
 }
}

Cheers, Lukas

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.