• 使用C#在开始菜单添加快捷方式实现开机自启动


    1. 添加引用:

    2.代码: 

    public static void SetAutoBootup(bool isAuto)
    {
        string fileName = ConfigCode.CLIENT_PROC_NAME;
        string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
        string startup = System.Environment.GetFolderPath(Environment.SpecialFolder.Startup);
        string shortPath = Path.Combine(startup, ConfigCode.PRODUCT_NAME+ ".lnk");
    
        if (!isAuto)
        {
            //不设置开机启动
            if (File.Exists(shortPath))
            {
                File.Delete(shortPath);
            }
        }
        else
        {
            //设置开机启动
            if (Directory.Exists(startup))
            {
                Directory.CreateDirectory(startup);
            }
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortPath);
            shortcut.TargetPath = filePath;
            shortcut.WorkingDirectory = Path.GetDirectoryName(filePath);
            shortcut.Arguments = "";
            shortcut.Description = ConfigCode.PRODUCT_NAME;
            shortcut.IconLocation = filePath + ", 0";
            shortcut.Save();
        }
  • 相关阅读:
    Swift -- 8.3 多态
    Swift -- 8.2 类的构造与析构
    Swift -- 8.1 继承
    Swift -- 7.6 构造器
    Swift -- 7.5 类型属性,方法
    Swift -- 7.4 方法,下标,可选链
    Swift -- 7.3 类和结构体
    Swift -- 7.2 枚举
    Swift -- 7.1 面向对象简介
    4-5轮选区的不透明度1.7
  • 原文地址:https://www.cnblogs.com/sanmao_net/p/9182701.html
Copyright © 2020-2023  润新知