首先分享一下写入,这个最常用的

public bool WriteRegedit() 
    { 
        try 
        { 
            RegistryKey rk = Registry.CurrentUser; 
            RegistryKey softWare = rk.OpenSubKey("Software"); 
            RegistryKey microsoft = softWare.OpenSubKey("Microsoft"); 
            RegistryKey windows = microsoft.OpenSubKey("Windows"); 
            RegistryKey current = windows.OpenSubKey("CurrentVersion"); 
            RegistryKey explorer = current.OpenSubKey("Explorer"); 
            RegistryKey shell = explorer.OpenSubKey(@"Shell Folders", true);//这里必须加true就是得到写入权限 
            RegistryKey key = shell.CreateSubKey("swort");//创建swort目录

key.SetValue("swort", "test"); 
            //在swort目录下建立写入swort test 
            Response.Write("写入成功!!!!!!!!!"); 
            return true; 
        } 
        catch 
        { 
            return false; 
        } 

 
接下来是给出一个操作网页的cs文件,大家看着调用就行
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Win32;
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("这里是读取到的信息"+"<br/>");
ReadRegedit();
Response.Write("<br/>");
Response.Write("这里将要写入信息swort/swort-test" + "<br/>");
WriteRegedit();
Response.Write("写入结束" + "<br/>");
Response.Write("查看存在与否" + "<br/>");
ExistsRegedit();
Response.Write("查看结束" + "<br/>");
Response.Write("删除" + "<br/>");
DeleteRegedit();
Response.Write("删除结束" + "<br/>");
Response.Write("查看存在与否" + "<br/>");
ExistsRegedit();
Response.Write("查看结束" + "<br/>");
}
/// <summary>
/// 注册表的读取
/// </summary>
/// <returns></returns>
public void ReadRegedit()
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders");
foreach (string b in shell.GetValueNames())//这里用shell.GetValueNames()不是shell.GetSubKeyNames()
{
Response.Write( b+" "+ shell.GetValue(b).ToString());
Response.Write("<br/>"); } }
/// <summary>
/// 注册表的写入
/// </summary>
/// <returns></returns>
public bool WriteRegedit()
{
try
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders", true);//这里必须加true就是得到写入权限
RegistryKey key = shell.CreateSubKey("swort");//创建swort目录
key.SetValue("swort", "test");
//在swort目录下建立写入swort test
Response.Write("写入成功!!!!!!!!!");
return true;
}
catch
{
return false;
} }
/// <summary>
/// 注册表的删除
/// </summary>
/// <returns></returns>
public bool DeleteRegedit()
{
try
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders",true);
RegistryKey swort = shell.OpenSubKey("swort",true);//这里必须加true就是得到写入权限
swort.DeleteValue("swort");//删除swort的值 这个连键值一起删除了 剩下一个
shell.DeleteSubKey("swort",false);//删除swort这个目录 要删除这个目录 必须具有权限 Response.Write("删除成功!!!!!!!!!");
return true;
}
catch
{
return false;
}
return true;
}
/// <summary>
/// 查询某个键值是否存在
/// </summary>
/// <returns></returns>
public bool ExistsRegedit()
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders");
if (shell.SubKeyCount != )
{
RegistryKey swort = shell.OpenSubKey("swort");
foreach (string b in swort.GetValueNames())
{
if (b == "swort")
{
Response.Write("存在这个键!");
return true;
} }
Response.Write("不存在这个键!");
return false;
}
else
{ Response.Write("不存在这个键!");
return false;
}
}
}

C#注册表的读,写,删除,查找的更多相关文章

  1. WINDOWS系统注册表(读、写)

    读取注册表 写入注册表

  2. vmware虚拟机卸载干净在注册表的也需要删除

  3. delphi 注册表操作(读取、添加、删除、修改)完全手册

    DELPHI VS PASCAL(87)  32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...

  4. 卸载oracle删除注册表脚本

    一.前言 在我们操作系统中,有时要卸载oracle数据库,每一次都要去删除win下的注册表,为了方便删除注册表的信息,下面通过一种删除注册表快捷的脚本. 二.脚本信息 Windows Registry ...

  5. Windows -- 从注册表删除IE浏览器加载项

    Windows -- 从注册表删除IE浏览器加载项 1.  一部分加载项从注册表以下位置直接删除 2.  一部分扩展项从注册表以下位置直接删除

  6. Delphi的注册表操作

    转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息.     一.创 ...

  7. C#综合揭秘——通过修改注册表建立Windows自定义协议

    引言 本文主要介绍注册表的概念与其相关根项的功能,以及浏览器如何通过连接调用自定义协议并与客户端进行数据通信.文中讲及如何通过C#程序.手动修改.安装项目等不同方式对注册表进行修改.其中通过安装项目对 ...

  8. 【转】C#综合揭秘——通过修改注册表建立Windows自定义协议

    引言 本文主要介绍注册表的概念与其相关根项的功能,以及浏览器如何通过连接调用自定义协议并与客户端进行数据通信.文中讲及如何通过C#程序.手动修改.安装项目等不同方式对注册表进行修改.其中通过安装项目对 ...

  9. Windows 注册表 (未完成)

    由于最近需要用到注册表,并且操作很多系统设置,所以想吧关于微软注册表的东西都写出来,找了很久才发现,微软对于注册表做了很详细的说明,但是为了节省时间翻译文本为自动翻译,手动纠错,欢迎大家指出错误. 根 ...

随机推荐

  1. [转]抓取安卓APP内接口的方法--Charles

    http://blog.csdn.net/yyh352091626/article/details/52759294

  2. [转] - 在mac的终端中使用sublime打开文件

    在mac的终端中使用sublime打开文件 使用sublime提供的命令行工具.这个命令行工具位于 /Applications/Sublime\ Text\ 2.app/Contents/Shared ...

  3. iOS - Safe iOS 加密安全

    1.Base64 编码 简介: Base64 是一种基于64个可打印字符来表示二进制数据的表示方法,可打印字符包括字母 A-Z.a-z.0-9,共 62 个字符,另外两个符号在不同的系统不同 +,/. ...

  4. web.Config配置数据库的连接

    <!--连接字符串设置--> <connectionStrings> <add name="ConnString" connectionString= ...

  5. js页面跳转(含框架跳转)整理

    js方式的页面跳转1.window.location.href方式    <script language="javascript" type="text/java ...

  6. C#如果把A.new()编译成new A()

    缘由 对于初次接触某个第三方库的C#开发者,假如要调用里面一个方法,发现需要一个A类型的实例作为参数,怎么获得这个实例呢? 我想大多数人会先尝试new A吧: 如果没有,可能会尝试输入A.看看有没可能 ...

  7. 用computed返回this.$store.state.count,store更改了,但是computed没有调用

    今天出现了这个问题,store更新了,你computed为啥不调用呢??? 另一个.vue更新了state,这个的computed就监听不到了么? 是用这种格式更新的this.$store.commi ...

  8. Python 修饰符

    def hello(fn):    def wrapper():        print "hello"        fn()        print "goodb ...

  9. 使用dreamweaver去掉文本中的空格和换行

    当我们从其他地方拷贝文本到网页,在html代码中会自动带有空格和换行,手动去掉很麻烦,今天试着用dreamweaver去了一下,方法如下: 1.点击Ctrl+F,打开“查找和替换”窗口 2‘见下图:

  10. java sqlhelper

    dbinfo.properties部分: 注意每行末尾不可以有空格 #oracle configure UserName=scott Password=tiger Driver=oracle.jdbc ...