zoukankan      html  css  js  c++  java
  • c# 创建快捷方式并添加到开始菜单程序目录

    Using the Windows Script Host (make sure to add a reference to the Windows Script Host Object Model, under References > COM tab):using IWshRuntimeLibrary;

    
    private static void AddShortcut()
    {
        string pathToExe = @"C:Program Files (x86)TestAppTestApp.exe";
        string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);//or Environment.GetFolderPath(Environment.SpecialFolder.Programs);
        string appStartMenuPath = Path.Combine(commonStartMenuPath, "Programs", "TestApp");
    
        if (!Directory.Exists(appStartMenuPath))
            Directory.CreateDirectory(appStartMenuPath);
    
        string shortcutLocation = Path.Combine(appStartMenuPath, "Shortcut to Test App" + ".lnk");
        WshShell shell = new WshShell();
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
    
        shortcut.Description = "Test App Description";
        //shortcut.IconLocation = @"C:Program Files (x86)TestAppTestApp.ico"; //uncomment to set the icon of the shortcut
        shortcut.TargetPath = pathToExe;
        shortcut.Save(); 
    }




    例子2:


    public static void CreateStartMenuShortcut()
        {
            string programs_path = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
            string shortcutFolder = Path.Combine(programs_path, @"MorganTechSpaceSampleApp");
            if (!Directory.Exists(shortcutFolder))
            {
                Directory.CreateDirectory(shortcutFolder);
            }
    
             WshShellClass shellClass = new WshShellClass();
            //Create First Shortcut for Application Settings
            string settingsLink = Path.Combine(shortcutFolder, "Settings.lnk");
            IWshShortcut shortcut = (IWshShortcut)shellClass.CreateShortcut(settingsLink);
            shortcut.TargetPath = @"C:Program FilesMorganTechSpaceMyAppSettings.exe";
            shortcut.IconLocation = @"C:Program FilesMorganTechSpacesettings.ico";
            shortcut.Arguments = "arg1 arg2";
            shortcut.Description = "Click to edit MorganApp settings";
            shortcut.Save();
    
            //Create Second Shortcut for Uninstall Setup
            string uninstallLink = Path.Combine(shortcutFolder, "Uninstall.lnk");
            shortcut = (IWshShortcut)shellClass.CreateShortcut(uninstallLink);
            shortcut.TargetPath = @"C:Program FilesMorganTechSpaceSetup.exe";
            shortcut.IconLocation = @"C:Program FilesMorganTechSpaceuninstall.ico";
            shortcut.Arguments = "u";
            shortcut.Save();
        }
    

      





  • 相关阅读:
    斑马打印交叉线制作方法
    c# 导出2007格式的Excel的连接字符串
    MySql数据库 timeout超时报警的解决方法
    c# 根据域名的到对应的IP
    c# 开发+MySql数据库
    c# datagridview导出Excel文件 问题
    ae GP制作缓冲区分析
    ae 地理坐标与投影坐标转换 [转]
    Dev Winform 简洁界面模板制作
    Dev TreeList 总结
  • 原文地址:https://www.cnblogs.com/wgscd/p/13954384.html
Copyright © 2011-2022 走看看