日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

C#-注册表操作

發布時間:2025/6/17 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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#-注册表操作的全部內容,希望文章能夠幫你解決所遇到的問題。

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