概述
(1)引用命名空间using Microsoft.Win32;
(2)利用registry类实现:注册表的读写删除操作,下面是我自己编写的一个类(该类主要实现针对一个特定的注册表键值进行的操作,可以稍加修改成一个通用的类)
public
class Reg
{
//给SOFTWARE目录下的“XXXX”项写值
public void writeREG(string count)
{
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
RegistryKey cameracount = software.CreateSubKey("XXXX");
cameracount.SetValue("count", count);
string names = Convert.ToString(cameracount.GetValue("count"));
}
<pre name="code" class="csharp">
//读取SOFTWARE目录下的“XXXX”项值
public string readREG()
{
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
RegistryKey cameracount = software.OpenSubKey("XXXX");
string count = Convert.ToString(cameracount.GetValue("count")); return count;
}
<span style="font-family: Arial, Helvetica, sans-serif;"> //SOFTWARE目录下的“XXXX”项</span>
public void deleteREG()
{
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
software.DeleteSubKey("XXXX", false);
}
//判断SOFTWARE目录下的“XXXX”项是否存在
public bool isExistREG()
{
bool exit = false;
string[] subkeyNames;
RegistryKey hkml = Registry.LocalMachine;
RegistryKey software = hkml.OpenSubKey("SOFTWARE", true);
subkeyNames = software.GetSubKeyNames();
foreach (string keyName in subkeyNames)
{
if (keyName == "XXXX")
{
exit = true;
return exit;
}
}
return exit;
}
最后
以上就是傻傻小懒虫为你收集整理的C#操作系统注册表using Microsoft.Win32;的全部内容,希望文章能够帮你解决C#操作系统注册表using Microsoft.Win32;所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复