1.生成文件快捷方式
//IWshRuntimeLibrary是com组件
//需要引用 Script Host Object Model 组件
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut("c://a.lnk");
shortcut.TargetPath = @"c:/a.txt";//文件物理地址
shortcut.Arguments = "";//参数
shortcut.Description = "附件快捷方式";
shortcut.Hotkey = "CTRL+SHIFT+N";
shortcut.IconLocation = "notepad.exe, 0";
shortcut.FullName = "打开163";
shortcut.Save();
2.生成ie快捷方式
IWshRuntimeLibrary.IWshShell_Class wshShell = new IWshRuntimeLibrary.IWshShell_ClassClass();
IWshRuntimeLibrary.IWshURLShortcut shortcut = wshShell.CreateShortcut(@"c:/a.url") as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = "http://www.youkuaiyun.com/";
//保存快捷方式
shortcut.Save();
生成ie快捷方式2
string SaveLnkDirectory = System.IO.Path.GetDirectoryName(filePath) + "//";
string fileName = System.IO.Path.GetFileNameWithoutExtension(filePath);
string fileLnkFullName = fileName + ".url";
string SaveLnkPath = SaveLnkDirectory + fileLnkFullName;
if (File.Exists(SaveLnkPath))
SaveLnkPath = SaveLnkDirectory + fileName+"1.url";
System.IO.StreamWriter objWriter = System.IO.File.CreateText(SaveLnkPath);
objWriter.WriteLine("[InternetShortcut]");
objWriter.WriteLine("URL=http://www.youkuaiyun.com/");
objWriter.Close();