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();
        }
    

      





  • 相关阅读:
    腾讯云学习笔记
    STL常见容器的理解
    C++STL
    Ubuntu:查看目录或文件信息 ls
    安装Ubuntu(通过U盘启动盘)
    C++基础知识
    C++ OpenCV常用的一些函数
    sqlite3主键,外键
    Windows下 Qt添加新模块
    IDE将C++源码生成为可执行文件过程
  • 原文地址:https://www.cnblogs.com/wgscd/p/13954384.html
Copyright © 2011-2022 走看看