加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C# 创建快捷方式 / 取快捷方式目标

发布时间:2020-12-15 17:53:26 所属栏目:百科 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 using System; using System.IO; using System.Runtime.InteropServices; class Program { static void Main(string[] args) { CreateShortCut( // 创

以下代码由PHP站长网 52php.cn收集自互联网

现在PHP站长网小编把它分享给大家,仅供参考

    using System;  
    using System.IO;  
    using System.Runtime.InteropServices;  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            CreateShortCut( // 创建快捷方式  
                    @"C:UserswindoDesktopican.lnk",@"%HOMEDRIVE%/Program FilesInternet ExplorerIEXPLORE.EXE",@"http://blog.csdn.net/u012395622",@"远去的山河 沉寂  恋过的风景 如昔",AppDomain.CurrentDomain.BaseDirectory,@"%HOMEDRIVE%/Program FilesInternet ExplorerIEXPLORE.EXE,0","CTRL+ALT+Z"  
                );  
      
        }  
      
        public static readonly Guid CLSID_WshShell = new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8");  
        public static string GetShortCutTarget(string lnk) // 取快捷方式目标  
        {  
            if (lnk != null && File.Exists(lnk))  
            {  
                dynamic objWshShell = null,objShortcut = null;  
                try  
                {  
                    objWshShell = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_WshShell));  
                    objShortcut = objWshShell.CreateShortcut(lnk);  
                    return objShortcut.TargetPath;  
                }  
                finally  
                {  
                    Marshal.ReleaseComObject(objShortcut);  
                    Marshal.ReleaseComObject(objWshShell);  
                }  
            }  
            return string.Empty;  
        }  
      
        public static bool CreateShortCut(string lnkFileName,string targetPath,string arguments,string remark,string workingDirectory,string iconLocation,string hotKey  
            )  
        {  
            if (lnkFileName != null && lnkFileName.Length > 0)  
            {  
                dynamic objWshShell = null,objShortcut = null;  
                try  
                {  
                    objWshShell = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_WshShell));  
                    objShortcut = objWshShell.CreateShortcut(lnkFileName);  
      
                    objShortcut.WindowStyle = 1;  
      
                    objShortcut.Hotkey = hotKey; // 热键  
                    objShortcut.TargetPath = targetPath; // 目标文件  
                    objShortcut.Arguments = arguments; // 参数  
                    objShortcut.Description = remark; // 备注  
                    objShortcut.WorkingDirectory = workingDirectory; // 起始位置  
                    objShortcut.IconLocation = iconLocation; // 图标位置  
      
                    objShortcut.Save();  
      
                    return true;  
                }  
                finally  
                {  
                    Marshal.ReleaseComObject(objShortcut);  
                    Marshal.ReleaseComObject(objWshShell);  
                }  
            }  
            return false;  
        }  
    }  

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究

如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读