要创建快捷方式需要用到IWshRuntimeLibrary命名空间,在这里我们要USING一下。并在引用里添加一个COM,windows script host object model。
具体创建如下:
Code
private void CreateShortCut()
{
string mysite = "http://" + iis + "/path/defaut.aspx";
IWshRuntimeLibrary.IWshShell_Class shell = new IWshRuntimeLibrary.IWshShell_ClassClass();
{
string fav = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\××××××××.url";
//定义快捷方式文件
IWshRuntimeLibrary.IWshURLShortcut shortcut = shell.CreateShortcut(fav) as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = mysite;
//保存快捷方式
shortcut.Save();
}
if (this.Context.Parameters["ckDesktop"] == "1")
{
string dsk = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\××××××××.url";
IWshRuntimeLibrary.IWshURLShortcut shortcut = shell.CreateShortcut(dsk) as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = mysite;
shortcut.Save();
}
}
private void CreateShortCut()
{
string mysite = "http://" + iis + "/path/defaut.aspx";
//创建Windows Script Host Shell类
IWshRuntimeLibrary.IWshShell_Class shell = new IWshRuntimeLibrary.IWshShell_ClassClass();
if (this.Context.Parameters["ckFavorites"] == "1")
{
string fav = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\××××××××.url";
//定义快捷方式文件
IWshRuntimeLibrary.IWshURLShortcut shortcut = shell.CreateShortcut(fav) as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = mysite;
//保存快捷方式
shortcut.Save();
}
if (this.Context.Parameters["ckDesktop"] == "1")
{
string dsk = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\××××××××.url";
IWshRuntimeLibrary.IWshURLShortcut shortcut = shell.CreateShortcut(dsk) as IWshRuntimeLibrary.IWshURLShortcut;
shortcut.TargetPath = mysite;
shortcut.Save();
}
}