【Unity-學習-007】 設置項目開機自啓動

// 設置開機自啓動
    public void SetAutoStart()
    {
        try
        {
            string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            if (rgkRun == null)
            {

                rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
            }
            rgkRun.SetValue("QuanXiLiShi", path); // 名字請自行設置
        }
        catch
        {
            Debug.Log(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
        }
        finally
        {
            Regeditkey();
        }

    }
    private void Regeditkey()
    {
        RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        if (rgkRun.GetValue("QuanXiLiShi") == null)
        {
            Debug.Log("自啓動爲關閉");
        }
        else
        {
            Debug.Log("自啓動爲打開");
        }
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章