diff --git a/Apewer.Windows/WindowsUtility.cs b/Apewer.Windows/WindowsUtility.cs
index e0410b2..88d1885 100644
--- a/Apewer.Windows/WindowsUtility.cs
+++ b/Apewer.Windows/WindowsUtility.cs
@@ -1039,17 +1039,21 @@ namespace Apewer
#if NETFX
- /// 创建快捷方式。
- /// 快捷方式路径。
+ /// 创建快捷方式,生成 .lnk 文件。
+ /// 快捷方式路径,以 .lnk 结尾。
/// 快捷方式图标。可使用 c:\source.exe,0 格式。
/// 快捷方式说明。
/// 源路径。
/// 源参数。
/// 工作目录。
+ ///
public static void CreateShortcut(string linkPath, string sourcePath, string sourceArgs = null, string linkIcon = null, string linkDescription = null, string directory = null)
{
// var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// var shortcut = (IWshShortcut)new WshShellClass().CreateShortcut(linkPath);
+ if (linkPath.IsEmpty()) throw new ArgumentNullException(nameof(linkPath));
+ if (sourcePath.IsEmpty()) throw new ArgumentNullException(nameof(sourcePath));
+
var wshShellClass = new IWshRuntimeLibrary.WshShellClass();
var wshObject = wshShellClass.CreateShortcut(linkPath);
var wshShortcut = (IWshRuntimeLibrary.IWshShortcut)wshObject;
@@ -1067,6 +1071,36 @@ namespace Apewer
#endif
+ /// 创建 URL 快捷方式,生成 .url 文件。
+ /// 快捷方式路径,以 .url 结尾。
+ /// URL。
+ /// 快捷方式图标。
+ /// 快捷方式图标索引。
+ ///
+ public static void CreateUrlShortCut(string linkPath, string url, string iconFilePath = null, int iconIndex = 0)
+ {
+ if (linkPath.IsEmpty()) throw new ArgumentNullException(nameof(linkPath));
+ if (url.IsEmpty()) throw new ArgumentNullException(nameof(url));
+
+ var lines = new List();
+ lines.Add("[{000214A0-0000-0000-C000-000000000046}]");
+ lines.Add("Prop3=19,11");
+ lines.Add("");
+ lines.Add("[InternetShortcut]");
+ lines.Add("IDList=");
+ lines.Add($"URL={url}");
+ if (StorageUtility.FileExists(iconFilePath))
+ {
+ lines.Add($"IconIndex={iconIndex}");
+ lines.Add("HotKey=0");
+ lines.Add($"IconFile={iconFilePath}");
+ }
+
+ var text = lines.Join("\r\n") + "\r\n";
+ var bytes = text.Bytes(Encoding.Default);
+ StorageUtility.WriteFile(linkPath, bytes);
+ }
+
#endregion
}