| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c# >> C#注册表的读,写,删除,查找 C# zhu ce biao de du , xie , shan chu , cha zhao
 

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

2008-09-25 07:47:54 编辑來源:互联网 繁體版 评论
 
 
本文为【C#注册表的读,写,删除,查找】的汉字拼音对照版显示拼音
  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("zhelishiduqudaodexinxi"+"<br/>");

   ReadRegedit();

   Response.Write("<br/>");

   Response.Write("zhelijiangyaoxieruxinxiswort/swort-test" + "<br/>");

   WriteRegedit();

   Response.Write("xierujieshu" + "<br/>");

   Response.Write("chakancunzaiyufou" + "<br/>");

   ExistsRegedit();

   Response.Write("chakanjieshu" + "<br/>");

   Response.Write("shanchu" + "<br/>");

   DeleteRegedit();

   Response.Write("shanchujieshu" + "<br/>");

   Response.Write("chakancunzaiyufou" + "<br/>");

   ExistsRegedit();

   Response.Write("chakanjieshu" + "<br/>");

   }

   /// <summary>

   /// zhucebiaodeduqu

   /// </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())//zheliyongshell.GetValueNames()bushishell.GetSubKeyNames()

   {

   Response.Write( b+" "+ shell.GetValue(b).ToString());

   Response.Write("<br/>");

  

   }

  

  

   }

   /// <summary>

   /// zhucebiaodexieru

   /// </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);//zhelibixujiatruejiushidedaoxieruquanxian

   RegistryKey key = shell.CreateSubKey("swort");//chuangjianswortmulu

   key.SetValue("swort", "test");

   //zaiswortmuluxiajianlixieruswort test

   Response.Write("xieruchenggong");

   return true;

   }

   catch

   {

   return false;

   }

  

   }

   /// <summary>

   /// zhucebiaodeshanchu

   /// </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);//zhelibixujiatruejiushidedaoxieruquanxian

   swort.DeleteValue("swort");//shanchuswortdezhi zhegelianjianzhiyiqishanchule shengxiayige

   shell.DeleteSubKey("swort",false);//shanchuswortzhegemulu yaoshanchuzhegemulu bixujuyouquanxian

  

   Response.Write("shanchuchenggong");

   return true;

   }

   catch

   {

   return false;

   }

   return true;

   }

   /// <summary>

   /// chaxunmougejianzhishifoucunzai

   /// </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("cunzaizhegejian");

   return true;

   }

   }

   Response.Write("bucunzaizhegejian");

   return false;

   }

   else

   { Response.Write("bucunzaizhegejian");

   return false;

   }

   }

  }原文】【拼音
 
 
 
 
上一篇《c#和javascript交互》
下一篇《C#关闭当前页面(借道JavaScript)》
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
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; } } }
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
时尚秀气模特裴裴(8)
时尚秀气模特裴裴(7)
时尚秀气模特裴裴(6)
时尚秀气模特裴裴(5)
白墙黑瓦
广州东郊[原创]
八美至丹巴的东谷天然盆景
不一样的
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
©2005- 王朝网络 版权所有