首页  ·  知识 ·  
Label
      编辑:  图片来源:网络

//首先引用Com下 Windows Script Host Object Model

using System.Runtime.InteropServices;    
using IWshRuntimeLibrary;

 

private void AddShortcut()
    {
        try
        {
            string mysite = "http://www.baidu.com";

            //创建收藏夹快捷方式
            string fav = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\百度.url";
            IWshShell_Class wshShell = new IWshShell_ClassClass();//创建 Windows Script Host Shell 类  
            IWshURLShortcut favShortcut = wshShell.CreateShortcut(fav) as IWshURLShortcut;//定义快捷方式文件   
             favShortcut.TargetPath = mysite;
            favShortcut.Save();//保存快捷方式


            //创建桌面快捷方式
            IWshShell_Class wshShell = new IWshShell_ClassClass();//创建 Windows Script Host Shell 类  
            string desktop = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\百度.url";
            IWshURLShortcut desktopShortcut = wshShell.CreateShortcut(desktop) as IWshURLShortcut;
            desktopShortcut.TargetPath = mysite;
            desktopShortcut.Save();//保存快捷方式
        }
        catch (Exception exc)
        {
            throw new Exception("创建快捷方式错误!" + exc.Message);
        }
    }

本文作者:wj4251591 来源: http://www.cnblogs.com/wj4251591/archive/2010/07/22/1782929.html
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的
收藏至微信