Add specific url to c # goal shortcut

Trying to create several different shortcuts for different desktop URLs using the following method:

public static void CreateShortcutWithURL(
    string shortcutName, string shortcutPath, string targetFileLocation)
{
    var shortcutLocation = Path.Combine(shortcutPath, shortcutName + ".lnk");
    var shell = new WshShell();
    var shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

    // The description of the shortcut
    //shortcut.Description = "My shortcut description";

    // The icon of the shortcut
    //shortcut.IconLocation = @"c:\myicon.ico";

    // The path of the file that will launch when the shortcut is run
    shortcut.TargetPath = $" \" {targetFileLocation} \" https://www.somewebsite.com";

    shortcut.Save();
}

Errors if I try to add anything to targetFileLocation.

I use it as follows:

CreateShortcutWithURL(
    "My Shortcut",
    Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
    @"C:\Program Files (x86)\Internet Explorer\iexplore.exe");

If I change this line in the method to this, it will end without errors:

shortcut.TargetPath = targetFileLocation ; 

The shortcut is placed on the desktop, but without the additional https://www.somewebsite.com added to the target, so it simply opens the browser without directing it to the website.

I am trying to create several shortcuts that open Explorer but make it navigate to certain websites.

+4
source share
1 answer

:

  • "" iexplore.exe
  • - ,

:

shortcut.TargetPath =" \" "+targetFileLocation+ " \" " + " https://www.somewebsite.com" ; 

:

shortcut.TargetPath = targetFileLocation;
shortcut.Arguments = @"https://www.google.com";

, .

+3

Source: https://habr.com/ru/post/1660403/


All Articles