日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

C#-注册表操作

發布時間:2025/6/17 C# 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C#-注册表操作 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; //對注冊表操作 using System.Collections; //使用Arraylist using System.Security.Cryptography;//加密解密 using System.IO; //文件操作 using System.Runtime.InteropServices;//調用DLL DllImport using System.Management; //獲取硬件信息 using System.Net; //獲取IP地址是用到 using System.Drawing; //image using System.Net.NetworkInformation; //ping 用到 using System.Text.RegularExpressions; //正則 using System.Data; using System.Data.SqlClient; using Microsoft.VisualBasic; //簡體轉繁體時用到 using System.Web; //html UrlEncode//注冊表操作public class GF_RegReadWrite{/// <summary>/// 讀取路徑為keypath,鍵名為keyname的注冊表鍵值,缺省返回def/// </summary>/// <param name="rootkey"></param>/// <param name="keypath">路徑</param>/// <param name="keyname">鍵名</param>/// <param name="rtn">默認為null</param>/// <returns></returns> static public bool GetRegVal(RegistryKey rootkey, string keypath, string keyname, out string rtn){rtn = "";try{RegistryKey key = rootkey.OpenSubKey(keypath);rtn = key.GetValue(keyname).ToString();key.Close();return true;}catch{return false;}}/// <summary>/// 設置路徑為keypath,鍵名為keyname的注冊表鍵值為keyval/// </summary>/// <param name="rootkey"></param>/// <param name="keypath"></param>/// <param name="keyname"></param>/// <param name="keyval"></param>/// <returns></returns>static public bool SetRegVal(RegistryKey rootkey, string keypath, string keyname, string keyval){try{RegistryKey key = rootkey.OpenSubKey(keypath, true);if (key == null)key = rootkey.CreateSubKey(keypath);key.SetValue(keyname, (object)keyval);key.Close();return true;}catch{return false;}}/// 創建路徑為keypath的鍵private RegistryKey CreateRegKey(RegistryKey rootkey, string keypath){try{return rootkey.CreateSubKey(keypath);}catch{return null;}}/// 刪除路徑為keypath的子項private bool DelRegSubKey(RegistryKey rootkey, string keypath){try{rootkey.DeleteSubKey(keypath);return true;}catch{return false;}}/// 刪除路徑為keypath的子項及其附屬子項private bool DelRegSubKeyTree(RegistryKey rootkey, string keypath){try{rootkey.DeleteSubKeyTree(keypath);return true;}catch{return false;}}/// 刪除路徑為keypath下鍵名為keyname的鍵值private bool DelRegKeyVal(RegistryKey rootkey, string keypath, string keyname){try{RegistryKey key = rootkey.OpenSubKey(keypath, true);key.DeleteValue(keyname);return true;}catch{return false;}}}

總結

以上是生活随笔為你收集整理的C#-注册表操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。