zoukankan      html  css  js  c++  java
  • c#创建快捷方式代码

    条件:

    COMWindows Script Host Object Model,然后可以通过以下方法创建快捷方式。

    方法:

    bool CrtShortCut(string FilePath, string fileName)
            {
                //MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory).ToString());
                //从COM中引用 Windows Script Host Object Model
                //再using IWshRuntimeLibrary;
                WshShell shell = new WshShell();

               //创建桌面快捷方式
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "//" + fileName + ".lnk");
                shortcut.TargetPath = FilePath;
                shortcut.WorkingDirectory = Environment.CurrentDirectory;
                shortcut.WindowStyle = 1;
                shortcut.Description = fileName;
                shortcut.Save();

               //创建开始菜单快捷方式
                IWshShortcut shortcut1 = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "//" + fileName + ".lnk");
                shortcut1.TargetPath = FilePath;
                shortcut1.WorkingDirectory = Environment.CurrentDirectory;
                shortcut1.WindowStyle = 1;
                shortcut1.Description = fileName;
                shortcut1.Save();
                return true;

            }

    调用:

    CrtShortCut("c://a.exe", "a.exe");

  • 相关阅读:
    设计模式二(建造者、原型、桥接)
    MSSQL根据表名动态分页的存储过程以及C#.net调用使用
    查询身份证号码信息(C#.NET)
    初试三层+抽象工厂代码生成器
    NET多线程与异步编程
    【SQL.SERVER.DMVS.实战】学习笔记
    【SQL.SERVER.DMVS.实战】学习笔记(二)
    SQL Server 2005数据文件数据的存储
    ASP.NET第九天加强课程
    ASP.NET第四天加强课程
  • 原文地址:https://www.cnblogs.com/liaomin416100569/p/9331626.html
Copyright © 2011-2022 走看看