/// <summary> /// 创建InternetShortcut /// </summary> /// <param name="path">快捷方式路径</param> /// <param name="targetPath">目标URL</param> public static void CreateURLShortcut(string path, string targetPath) { WshShell shell = new WshShellClass(); WshURLShortcut urlShortcut = shell.CreateShortcut(path) as WshURLShortcut; urlShortcut.TargetPath = targetPath; urlShortcut.Save(); }
/// <summary> /// Verify that the target of a Shortcut /// </summary> /// <param name="path">Path were the Internet short cuts should be created</param> /// <param name="target">expected target</param> /// <param name="linkType">is it a .lnk or a .url</param> public static void VerifyInterNetShortCutTarget(string path, string target, LinkType linkType) { if (System.IO.File.Exists(path)) { if (linkType == LinkType.Link) { WshShell shell = new WshShell(); IWshShortcut link = (IWshShortcut)shell.CreateShortcut(path); Assert.True(link.TargetPath.Equals(target), String.Format("Shourtcut '{0}' target does not match expected. Actual: '{1}'. Expected: '{2}'.", path, link.TargetPath, target)); } else if (linkType == LinkType.URL) { WshShell shell = new WshShell(); WshURLShortcut link = (WshURLShortcut)shell.CreateShortcut(path); Assert.True(link.TargetPath.Equals(target), String.Format("URL Shourtcut '{0}' target does not match expected. Actual: '{1}'. Expected: '{2}'.", path, link.TargetPath, target)); } } else { Assert.True(false, String.Format("File '{0}' was not found; it was expected to.", path)); } }