C#操作注冊表簡單方法實現(xiàn)
作者:佚名
C#操作注冊表簡單方法實現(xiàn)主要向你介紹了C#操作注冊表的一個簡單的過程,希望對你了解和學習C#操作注冊表有所幫助。
C#操作注冊表方面前言:使用VC,VB等語言操作注冊表的例子已經(jīng)有很多了,其實在C#操作注冊表更加的簡單方便。下面的例子就提供了在C#里操作注冊表的方法:
- using Microsoft.Win32;
- //C#操作注冊表
- using System.Diagnostics;
- private void Access_Registry()
- {
- // 在HKEY_LOCAL_MACHINESoftware下建立一新鍵,起名為MCBInc
- RegistryKey key = Registry.LocalMachine.OpenSubKey("Software", true);
- // 增加一個子鍵
- RegistryKey newkey = key.CreateSubKey("MCBInc");
- // 設(shè)置此子鍵的值
- newkey.SetValue("MCBInc", "NET Developer");
- // 從注冊表的其他地方獲取數(shù)據(jù)
- //C#操作注冊表
- // 找出你的CPU
- RegistryKey pRegKey = Registry.LocalMachine;
- pRegKey = pRegKey.OpenSubKey("HARDWAREDESCRIPTIONSystemCentralProcessor");
- Object val = pRegKey.GetValue("VendorIdentifier");
- Debug.WriteLine("The central processor of this machine is:"+ val);
- // 刪除鍵值 ,C#操作注冊表
- RegistryKey delKey = Registry.LocalMachine.OpenSubKey("Software", true);
- delKey.DeleteSubKey("MCBInc");
- }
C#操作注冊表的簡單例子就向你講解到這里,希望對你學習和了解C#操作注冊表有所幫助。
【編輯推薦】
責任編輯:仲衡
來源:
builder.com.cn