zoukankan      html  css  js  c++  java
  • 在C#中快速创建快捷方式到指定位置

    以下步骤调用WSH对象在客户端机器创建快捷方式

    1 在项目中添加对Windows Script Host Object Mode的引用,这个组件在添加引用对话框的COM类别中

    2 在CS文件中添加对该对象的引用,如下代码:using IWshRuntimeLibrary

    3 下面这个函数演示使用WSH对象添加快捷方式到指定的位置:

    public bool AddShortCut(Environment.SpecialFolder folderType,string targetDir,string linkName)
    {
           try
           {
                 string folder = Environment.GetFolderPath(folderType) + "\\" + linkName;
                 // Create a Windows Script Host Shell class
                 IWshShell_Class shell = new IWshShell_ClassClass();
                // Define the shortcut file
                IWshShortcut_Class shortcut = shell.CreateShortcut(folder + ".lnk") as IWshShortcut_Class;
                shortcut.TargetPath = targetDir;
                shortcut.Save();   
                return true; 
           }
           catch (Exception ex)
           {
                   return false;
            }     
    }

    例如

    AddShortCut(Environment.SpecialFolder.Programs,http://locahost/MSPortal,"企业门户");

    是否可以将以上代码段用于WebForm程序中还需要测试,目前是在开发机器本机IE调用可以正常运行,但是对于其他机器客户端访问就不能生成快捷方式

  • 相关阅读:
    c# 设计模式 之:装饰模式
    c# 设计模式 之:抽象工厂
    c# 设计模式 之:简单工厂、工厂方法、抽象工厂之小结、区别
    c# 设计模式 之:工厂模式之---工厂模式
    c# 设计模式 之:工厂模式之---简单工厂
    uml
    ASP.NET应用程序生命周期
    C语言可变参数个数
    软件开发过程中的视角
    UML类图与类的关系详解
  • 原文地址:https://www.cnblogs.com/xqyi/p/75511.html
Copyright © 2011-2022 走看看