Unity设置自启动项目
2016-12-06 17:30
369 查看
今天在蛮牛上看到一篇设置unity导出的程序自启动项目,感觉还不错,源码如下:
using UnityEngine;
using System.Collections;
using Microsoft.Win32;
using UnityEngine.UI;
public class test : MonoBehaviour
{
public Button Btn1;
public Button Btn2;
public Text text;
void OnEnable()
{
Btn1.onClick.AddListener(OnBtn1Click);
Btn2.onClick.AddListener(OnBtn2Click);
}
void OnDisable()
{
Btn1.onClick.RemoveListener(OnBtn1Click);
Btn2.onClick.RemoveListener(OnBtn2Click);
}
private void OnBtn1Click()
{
//MessageBox.Show("设置开机自启动,需要修改注册表", "提示");
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("dhstest", path);
}
catch
{
Debug.Log(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
finally
{
regeditkey();
Debug.Log(123);
}
}
private void OnBtn2Click()
{
//MessageBox.Show("取消开机自启动,需要修改注册表", "提示");
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.DeleteValue("dhstest", false);
}
catch
{
Debug.Log("error");
}
finally
{
regeditkey();
Debug.Log(123);
}
}
public void regeditkey()
{
Debug.Log(123);
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun.GetValue("dhstest") == null)
{
text.text = "自启动为关闭";
}
else
{
text.text = "自启动为打开";
}
}
}
using UnityEngine;
using System.Collections;
using Microsoft.Win32;
using UnityEngine.UI;
public class test : MonoBehaviour
{
public Button Btn1;
public Button Btn2;
public Text text;
void OnEnable()
{
Btn1.onClick.AddListener(OnBtn1Click);
Btn2.onClick.AddListener(OnBtn2Click);
}
void OnDisable()
{
Btn1.onClick.RemoveListener(OnBtn1Click);
Btn2.onClick.RemoveListener(OnBtn2Click);
}
private void OnBtn1Click()
{
//MessageBox.Show("设置开机自启动,需要修改注册表", "提示");
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("dhstest", path);
}
catch
{
Debug.Log(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
}
finally
{
regeditkey();
Debug.Log(123);
}
}
private void OnBtn2Click()
{
//MessageBox.Show("取消开机自启动,需要修改注册表", "提示");
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.DeleteValue("dhstest", false);
}
catch
{
Debug.Log("error");
}
finally
{
regeditkey();
Debug.Log(123);
}
}
public void regeditkey()
{
Debug.Log(123);
RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rgkRun.GetValue("dhstest") == null)
{
text.text = "自启动为关闭";
}
else
{
text.text = "自启动为打开";
}
}
}
相关文章推荐
- 设置unity 编译文件到android项目
- Unity5 项目设置 .gitignore 解决 Missing Prefab 问题
- 项目设置player设置里设置分辨率 unity输出竖屏等
- unity项目去除unity开始动画和发布设置
- workman项目设置开机自启动
- unity项目去除unity开始动画和发布设置
- unity项目去除unity开始动画和发布设置
- workman项目设置开机自启动
- Unity项目中使用Git管理代码的设置步骤
- Unity3D设置Webgl项目支持手机访问
- 开发环境中biztalk项目设置注意事项
- ASP.NET中动态修改web.config中的设置项目(CS页代码)(转贴)
- [Symbian项目进展]如何实现手机中应用程序的开机自启动,附源代码
- ASP.NET程序中动态修改web.config中的设置项目(前台页面代码)
- 使用log4net-1.2.0-beta8 在项目的AssemblyInfo.cs文件中设置
- VC常用项目参数设置比较
- C#编码标准指导和最佳实践 之 项目设置和项目结构
- Linux自启动设置详解
- 通过设置项目输出XML文档,来强制要求写注释
- ASP.NET程序中动态修改web.config中的设置项目(后台CS代码)