尝试使用以下方法在桌面上为各种 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添加到目标 - 所以它只是打开浏览器而不将其定向到网站。
我正在尝试创建一些打开资源管理器的快捷方式,但使其导航到特定网站。
最佳答案
有两点是错误的:
- 在 iexplore.exe 的路径周围不需要
""
- 不能在路径中加上网址,必须是参数
更改以下代码:
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/