c# - 将特定 URL 添加到快捷方式 objective-c #

标签 c# visual-studio

尝试使用以下方法在桌面上为各种 URL 创建几个不同的快捷方式:

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

如果我尝试向 targetFileLocation 添加任何内容,它会出错。

我是这样使用的:

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

如果我将方法中的这一行更改为此,它会无错误地完成:

shortcut.TargetPath = targetFileLocation ; 

快捷方式放在桌面上 - 但没有额外的 https://www.somewebsite.com添加到目标 - 所以它只是打开浏览器而不将其定向到网站。

我正在尝试创建一些打开资源管理器的快捷方式,但使其导航到特定网站。

最佳答案

有两点是错误的:

  1. 在 iexplore.exe 的路径周围不需要 ""
  2. 不能在路径中加上网址,必须是参数

更改以下代码:

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

对此:

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

方法的其余部分就这样了。

关于c# - 将特定 URL 添加到快捷方式 objective-c #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40529637/

相关文章:

c# - Entity Framework 代码首次迁移 : get sql scripts programmatically

c# - 如何在 C# 中为接受 IComparable 的通用方法处理 double.NaN

c++ - Visual Studio 如何将 boost::function 与/GR- 一起使用,而 GCC 不能与 -fno-rtti 一起使用?

visual-studio - Visual Studio 2013(和 ReSharper)使用哪些文件夹?

c# - LoadFromContext 发生 (Wex.Logger.Interop)

c# - 一次写一条记录,用一个静态类?

c# - 配置 Entity Framework 以从 Azure CloudConfiguration 文件中选择连接字符串?

c# - 通用左侧界面参数

Git for Windows 停止工作 - VS Team Services

c++ - Boost 单元测试和 Visual Studio 2005/Visual C++ 以及 BOOST_AUTO_TEST_SUITE(stringtest) 命名空间?