zoukankan      html  css  js  c++  java
  • winform程序开机自动启动

    app.manifest

     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

     /// <summary>  
            /// 在注册表中添加、删除开机自启动键值  
            /// </summary>  
            public static int SetAutoBootStatu(bool isAutoBoot)
            {
                try
                {
                    string execPath = Application.ExecutablePath;
                    RegistryKey rk = Registry.LocalMachine;
                    RegistryKey rk2 = rk.CreateSubKey("Software\Microsoft\Windows\CurrentVersion\Run");
                    if (isAutoBoot)
                    {
                        rk2.SetValue("MyExec", execPath);
                        Console.WriteLine(string.Format("[注册表操作]添加注册表键值:path = {0}, key = {1}, value = {2} 成功", rk2.Name, "TuniuAutoboot", execPath));
                    }
                    else
                    {
                        rk2.DeleteValue("MyExec", false);
                        Console.WriteLine(string.Format("[注册表操作]删除注册表键值:path = {0}, key = {1} 成功", rk2.Name, "TuniuAutoboot"));
                    }
                    rk2.Close();
                    rk.Close();
                    return 0;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(string.Format("[注册表操作]向注册表写开机启动信息失败, Exception: {0}", ex.Message));
                    return -1;
                }
            }
  • 相关阅读:
    Comparator
    Compare接口
    Predicate接口和Consumer接口
    Lambda表达式遍历集合
    Lambda表达式入门
    RansomNote
    FirstUniqueCharacterInString
    String All Methods
    形参个数可变的方法(...)
    springBoot excel导出 下载 超简单
  • 原文地址:https://www.cnblogs.com/gaocong/p/8945204.html
Copyright © 2011-2022 走看看