C#-注册表操作
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32; //對(duì)注冊(cè)表操作
using System.Collections; //使用Arraylist
using System.Security.Cryptography;//加密解密
using System.IO; //文件操作
using System.Runtime.InteropServices;//調(diào)用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; //簡(jiǎn)體轉(zhuǎn)繁體時(shí)用到
using System.Web; //html UrlEncode//注冊(cè)表操作public class GF_RegReadWrite{/// <summary>/// 讀取路徑為keypath,鍵名為keyname的注冊(cè)表鍵值,缺省返回def/// </summary>/// <param name="rootkey"></param>/// <param name="keypath">路徑</param>/// <param name="keyname">鍵名</param>/// <param name="rtn">默認(rèn)為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>/// 設(shè)置路徑為keypath,鍵名為keyname的注冊(cè)表鍵值為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;}}/// 創(chuàng)建路徑為keypath的鍵private RegistryKey CreateRegKey(RegistryKey rootkey, string keypath){try{return rootkey.CreateSubKey(keypath);}catch{return null;}}/// 刪除路徑為keypath的子項(xiàng)private bool DelRegSubKey(RegistryKey rootkey, string keypath){try{rootkey.DeleteSubKey(keypath);return true;}catch{return false;}}/// 刪除路徑為keypath的子項(xiàng)及其附屬子項(xiàng)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;}}}
總結(jié)
- 上一篇: C#-鼠标操作
- 下一篇: c# char unsigned_dll