using System.Runtime.InteropServices;
using IWshRuntimeLibrary; // 添加引用:COM下Windows Script Host Object Model public bool Createlnk()
{
string app = "http://www.cnblogs.com/iack";
string location1 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\iack在cnblogs.url";
string location2 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + "\\iack在cnblogs.url";
string location3 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Programs) + "\\iack在cnblogs.url"; try
{
// Create a Windows Script Host Shell class
IWshShell_Class shell = new IWshShell_ClassClass();
// Define the shortcut file
IWshURLShortcut shortcut = shell.CreateShortcut(location1) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save(); shortcut = shell.CreateShortcut(location2) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save(); shortcut = shell.CreateShortcut(location3) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save(); return true;
} catch (COMException ex)
{
Console.WriteLine(ex.Message);
return false;
}
}

如果要自定义快捷链接的图标,请使用

using System.Runtime.InteropServices;
using IWshRuntimeLibrary; // 添加引用:COM下Windows Script Host Object Model public bool Createlnk()
{
string app = "c:\windows\system32\calc.exe";
string lnklocation = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + "\\计算器.lnk";
try
{
// Create a Windows Script Host Shell class
IWshShell_Class shell = new IWshShell_ClassClass();
// Define the shortcut file
IWshShortcut_Class shortcut = shell.CreateShortcut(lnklocation) as IWshShortcut_Class;
shortcut.TargetPath = app;
shortcut.Description = lnkDesc;
shortcut.IconLocation = app + ",0"; shortcut.Save();
return true;
}
catch (COMException ex)
{
Console.WriteLine(ex.Message);
return false;
}
}

可以实现自定义图标。:

【转载】C#.Net 创建网页快捷方式的更多相关文章

  1. (转)Inno Setup入门(四)——为程序创建桌面快捷方式

    本文转载自:http://blog.csdn.net/augusdi/article/details/8564810 Icons这一可选段定义所有创建在开始菜单和\或其它位置 (比如桌面) 的快捷方式 ...

  2. 小技巧(一):将文本文件txt或网页快捷方式固定到win10开始菜单

    win10不知道怎么回事不支持将文本文件和网页快捷方式固定到开始菜单 解决方法: 利用cmd 创建一个快捷方式: 路径:cmd /A /C  C:\Users\Admin\Desktop\test.t ...

  3. Ubuntu创建桌面快捷方式

    默认情况下,ubuntu会将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制-桌面 就Ok,如图: 上面的方法是通过系统自 ...

  4. 手机APP创建桌面快捷方式

    预览: 需要权限:   <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT& ...

  5. Windows中创建桌面快捷方式

    Windows中创建桌面快捷方式 -------------- -------------- -------------- --------------

  6. WPF 创建桌面快捷方式

    #region 创建桌面快捷方式 string deskTop = System.Environment.GetFolderPath(System.Environment.SpecialFolder. ...

  7. 解决Inno Setup制作安装包无法创建桌面快捷方式的问题

    转自:http://yedward.net/?id=104 昨天想把个java程序做成exe安装软件,然后就去下载了Inno Setup这个软件安装包制作软件,Inno Setup这个软件确实非常好用 ...

  8. C#创建桌面快捷方式 和 开机启动

              /// <summary>         /// 创建桌面快捷方式 2010-11-25         /// </summary>         p ...

  9. android 为应用程序创建桌面快捷方式技巧分享

    手机装的软件过多,找起来很不方便,所以在主页面有一个快捷方式的话会很不错的,本文将介绍如何实现,需要了解跟多的朋友可以参考下     我们开发一款软件后,如果手机装的软件过多,去翻的话会很难翻的,所以 ...

随机推荐

  1. C语言知识总结(4)

    变量的作用域 C语言根据变量作用域的不同,将变量分为局部变量和全局变量 1.局部变量 1> 定义:在函数内部定义的变量,称为局部变量.形式参数也属于局部变量. 2> 作用域:局部变量只在定 ...

  2. c#中sqlhelper类的编写(二)

    上一篇文章讲了简易版的SqlHelper类的编写,我们在这里就上一篇文章末尾提出的问题写出解决方案. sql语句注入攻击已经是众所周知的了.我们如何在C#中保护自己的数据库不被这样的方式攻击呢? 不用 ...

  3. 20141104--SQL,查询习题,约束

    --创建学生信息表:学号,姓名,班级,性别,语文教师,数学教师,英语教师 --创建一个教师表:编号,姓名,课程,性别,出生日期 --创建一个分数表:语文,数学,外语,学号 --查询 语文成绩最高的学生 ...

  4. UI3_CustomUITableViewCell

    // AppDelegate.m // UI3_CustomUITableViewCell // // Created by zhangxueming on 15/7/15. // Copyright ...

  5. AMQ学习笔记 - 11. Spring-JmsTemplate之执行

    概述 前面我们分别介绍了发送.接收和浏览,这三个的实现都依赖于将要介绍的执行. 执行算是一个相对比较底层的方法系列,一般情况下,我们不需要直接面向将要介绍的方法. 执行 1.关于回调接口 在讲执行之前 ...

  6. Grunt 认识

    基本工作流: JS合并.JS压缩.CSS压缩.CSS Sprite.图片优化.测试.静态资源缓存(版本更新)... 基于工作流产生的工具: JSHint(jshint.com).CSSLint(css ...

  7. Windows phone 中一些实用的控件

    一.TextBlock:这个控件其实就是Label控件. <TextBlock x:Name="PageTitle" Text="page name" M ...

  8. 大仙说道之Android studio实现Service AIDL

    今天要开发过程中要用到AIDL的调用,之前用的eclipse有大量教程,用起来很方便,现在刚换了Android studio,不可否认studio真的很强大,只是很多功能还需要摸索. AIDL(And ...

  9. git 的使用(4)-git暂缓区工作区原理和修改删除等命令

    文章转载自:http://blog.csdn.net/think2me/article/details/39056379 博主说未经本人允许,不得转载,那就不贴了,拷贝关键部分作备忘 1. 暂存区是G ...

  10. 封装getElementsByClassName

    function getElementsByClassName(oEle,sClass,sEle){ if(oEle.getElementsByClassName){ return oEle.getE ...