今天有个需求window 平台的注册表, 本来unity3D 可以使用自带的PlayerPrefs 来完成,但是 外部Window 程序访问就比较麻烦了! 所有想使用 .net 自带的 API 去完成注册表的读写操作。 找了一大圈之后 发现 自从 window7 以后版本就使用不了了! 所有 雅虎 搜索 了一下 找出来了。和大家分享下:
代码如下: unity3d 和 ConsoleApplication 都能够读写
using UnityEngine;
using System.Collections;
using Microsoft.Win32;
public class RegeditController : MonoBehaviour {
// Use this for initialization
void Start()
{
ReadRegedit();
}
static void ReadRegedit()
{
RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("GOGOGO");
if (key != null) //说明存在
{
if (key.GetValue("AA") != null)
{
Debug.Log(key.GetValue("AA"));
}
}
key.Close();
}
static void WriteRegedit()
{
RegistryKey key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("GOGOGO");
key.SetValue("AA", @"E:\WorlSpace\Visual studio 2015\AliyunOss\ConsoleApplicationAliyunOss\ConsoleApplicationAliyunOss\ConsoleApplicationAliyunOss\bin\Debug");
key.Close();
}
}