网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 手机学院 | 邮件系统 | 网络安全 | 认证考试
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > C#应用
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.Visual c#的Excle编程.
.如何在控件的设计时得到窗体设计.
.用C#实现FTP搜索引擎.
.js也可以有自定义事件 注入就是这.
.关于c#中的事件处理机制.
.Web Service的几个很重要的概念 .
.在c#中实现3层架构.
.自定义应用程序配置文件(app.co.
.C#合并多个结构一样的Excel.
.C#中的接口.
.C#减少图片文件大小和尺寸.
.C#关闭当前页面(借道JavaScript).
.百万程序员的苦恼-选择VB.NET还.
.用C#开发.NET CF 蓝牙通信模块.
.关于C#中的DLLImport.
.c# 实现Word联接Excel的MailMerg.
.C#程序模拟鼠标操作 [Simulate M.
.IP数据包的校验和算法C#版.
.用C#访问ACCESS数据库问题.
.C#列出局域网中可用SQL Server服.

C#注册表的读,写,删除,查找

发表日期:2008-9-24

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 != 0)
        {
            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#关闭当前页面(借道JavaScript) 人气:2396
下一篇:C#引用Excel找不到类型或命名空间名称“Excel” 人气:1245
浏览全部C#的内容 Dreamweaver插件下载 网页广告代码 2009年新年快乐