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

      





  • 相关阅读:
    浏览器刷新缓存机制
    Asp.Net获取IP的方法
    c# 了解委托
    用什么方法来判断字符串是否存在的函数
    怎么样从地址中获得数据?
    新网站如何不被百度查封,请注意以下事项。
    搜索引擎如何抓取网页和如何索引网页?
    什么情况下include_path不起作用?
    用户注册演示程序操作案例
    用户提交的cookie提交时为什么传不到服务器
  • 原文地址:https://www.cnblogs.com/wgscd/p/13954384.html
Copyright © 2020-2023  润新知