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调用可以正常运行,但是对于其他机器客户端访问就不能生成快捷方式

  • 相关阅读:
    htmlUnil-2.33 jar包
    HtmlUnil 不兼容问题
    Java 网页抓取 工具类
    浏览器不兼容
    Chrome常用调试技巧1
    关于社交网络的思考
    google浏览器历史旧版
    EJB是什么Java使用EJB容器的详细概述
    何必言精通——十年杂感(转载)
    搜索优化—如何在Google搜索引擎上排名靠前Google左侧排名
  • 原文地址:https://www.cnblogs.com/xqyi/p/75511.html
Copyright © 2011-2022 走看看