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?
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();
}
}