惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 沉默天蝎的学习汇集

由浅入深:Python 中如何实现自动导入缺失的库?(转) itchat初步解读登录(转) 转:【开源必备】常用git命令 2.转发。基于itchat的微信消息同步机器人 1、初学探讨PYTHON的itchat和wxpy两库 学习git 新手。这个写的不错 转:android学习帖子大汇集 bat 切换单位和宿舍IP地址(转) (转)C#2Android [转]HTTP调试工具:Fiddler的使用方法介绍 使用VS2005的 ClickOnce 技术实现按需下载组件 转帖:麻雀虽小,五脏俱全-C# 创建windows服务、socket通讯实例 C# WinForm开发系列 - 文章索引 (转自peterzb) 非常经典的网络蜘蛛示例,我是转载在这里的 - 沉默天蝎的学习汇集 - 博客园 (转)三种模拟自动登录和提交POST信息的实现方法 (转自Timon's wang blogs)C#实现web信息自动抓取 sql2005安装产生问题解决汇集 (转自斯克迪亚的博客)学柯南,用电脑拨电话! 看完最新的柯南后很好奇,正好有人写到了就转来了 转贴:VS2008如何转换为VS2005
(转)c#操作注册表大全 - 沉默天蝎的学习汇集 - 博客园
沉默天蝎的学习汇集 · 2009-09-06 · via 博客园 - 沉默天蝎的学习汇集

1.打开键
//using Microsoft.Win32;
RegistryKey rkLocalM = Registry.LocalMachine; //Registry.ClassesRoot, Registry.LocalMachine, Registry.Users, Registry.CurrentConfig
const string strSubKey = %%1; //@"SOFTWARE\ODBC\ODBC.INI\DBNewTest\Test"
RegistryKey rkSub = rkLocalM.OpenSubKey( strSubKey );
//rkLocalM = Registry.LocalMachine; //Registry.ClassesRoot, Registry.LocalMachine, Registry.Users, Registry.CurrentConfig
//rkLocalM.OpenSubKey(%%1);

2.添加键
//using Microsoft.Win32;
RegistryKey rkLocalM = Registry.LocalMachine; //Registry.ClassesRoot, Registry.LocalMachine, Registry.Users, Registry.CurrentConfig
const string strSubKey = %%1; //@"SOFTWARE\ODBC\ODBC.INI\DBNewTest\Test"
RegistryKey rkSub = rkLocalM.CreateSubKey( strSubKey );
rkLocalM.Close();

3.删除键
rkSub.DeleteSubKey( %%1, false );

4.枚举第一个键
//using System.Collections;
IEnumerator<string> it = SubKey.GetSubKeyNames().First();
string %%1=it.Current;

5.枚举下一个键
string %%1=null;
if(it.MoveNext());
%%1=it.Current;

6.获取DWORD值
%%2=rkSub.GetValue(%%1);

7.获取二进制值
%%2=rkSub.GetValue(%%1);

8.读取字符串值
%%2=rkSub.GetValue(%%1);

9.写入字符串值
rkSub.SetValue( %%1, "Test" );

10.写入二进制值
rkSub.SetValue(%%1, value, RegistryValueKind.Binary);

11.写入DWORD值
rkSub.SetValue(%%1, value, RegistryValueKind.DWord);

12.设置DWORD值
rkSub.Add(%%1, value, RegistryValueKind.DWord);

13.删除值
rkSub.DeleteValue( %%1, false );//"DriverID"

14.关闭键
rkSub.Close();

15.列出一个键下所有的子键
string[] strSubKeys = rkSub.GetSubKeyNames();
for( int i = 0; i < strSubKeys.Length; i++ )
{
string %%1= strSubKeys[i] ;
%%2
}

16.列出一个键下所有的值
string[] strData = rkSub.GetValueNames();
for( int i = 0; i < strData.Length; i++ )
{
//Debug.WriteLine( string.Format( "{0}:{1}", strData[i], rkSub.GetValue( strData[i] ) ) );
}

17.列出一个键下所有的子键和值
string[] strSubKeys = rkSub.GetSubKeyNames();
for( int i = 0; i < strSubKeys.Length; i++ )
{
string %%1=strSubKeys[i];
%%2
}
string[] strData = rkSub.GetValueNames();
for( int i = 0; i < strData.Length; i++ )
{
//Debug.WriteLine( string.Format( "{0}:{1}", strData[i], rkSub.GetValue( strData[i] ) ) );
}

18.枚举所有的子键和值
//using Microsoft.Win32;
private static void Access_Registry(RegistryKey keyR, String str)
{
string[] subkeyNames;
string[] subvalueNames;
try
{
RegistryKey aimdir = keyR.OpenSubKey(str, true);
subvalueNames = aimdir.GetValueNames();
foreach (string valueName in subvalueNames)
{
if (valueName.ToUpper().IndexOf(%%1) > -1) //"XMS"
{
Console.WriteLine(valueName);
}
string value = aimdir.GetValue(valueName) as string;
if (value != null)
{
if (value.ToUpper().IndexOf(%%1) > -1) //"XMS"
{
Console.WriteLine(value);
}

}
}
subkeyNames = aimdir.GetSubKeyNames();
foreach (string keyName in subkeyNames)
{
if (keyName.ToUpper().IndexOf(%%1) > -1) //"XMS"
{
Console.WriteLine(keyName);
}
Access_Registry(aimdir, keyName);
}
}
catch (Exception) { }
}

RegistryKey[] keys ={ Registry.ClassesRoot, Registry.LocalMachine, Registry.CurrentUser, Registry.CurrentConfig };
foreach (RegistryKey key in keys)
{
string[] subkeyNames = key.GetSubKeyNames();
foreach (string keyName in subkeyNames)
{
Access_Registry(key, keyName);
}
key.Close();
}

19.模糊搜索所有的子键和值,查找特定字符串并删除
//using System.Collections;using Microsoft.Win32;
RegistryKey[] keys ={ Registry.LocalMachine, Registry.Users };// Registry.ClassesRoot, Registry.CurrentConfig
foreach (RegistryKey key in keys)
{
string[] subkeys = key.GetSubKeyNames();
Queue<String> al = new Queue<String>(subkeys);
Queue<RegistryKey> qu = new Queue<RegistryKey>();
for (int i = 0; i < subkeys.Length; i++)
qu.Enqueue(key);
while (al.Count > 0)
{
string[] subkeyNames;
string[] subvalueNames;
try
{
RegistryKey aimdir = qu.Dequeue();
aimdir = aimdir.OpenSubKey(al.Dequeue(), true);
subvalueNames = aimdir.GetValueNames();
foreach (string valueName in subvalueNames)
{
if (valueName.Equals("XMS", StringComparison.OrdinalIgnoreCase)) //%%1
{
aimdir.DeleteValue(valueName, false);
}
else
{
string value = aimdir.GetValue(valueName) as string;
if (value != null)
{
if (value.Equals("XMS", StringComparison.OrdinalIgnoreCase))
{
aimdir.DeleteValue(value, false);
}
}
}
}
subkeyNames = aimdir.GetSubKeyNames();
foreach (string keyName in subkeyNames)
{
if (keyName.Equals("XMS", StringComparison.OrdinalIgnoreCase))
{
aimdir.DeleteSubKey(keyName, false);
}
al.Enqueue(keyName);
qu.Enqueue(aimdir);
}
}
catch (Exception) { }
}
key.Close();
}

20.清空一个子键
//using Microsoft.Win32;
RegistryKey rkLocalM = Registry.LocalMachine; //Registry.ClassesRoot, Registry.LocalMachine, Registry.Users, Registry.CurrentConfig
const string strSubKey = %%1; //@"SOFTWARE\ODBC\ODBC.INI"
RegistryKey rkSub = rkLocalM.OpenSubKey( strSubKey, true );
rkSub.DeleteSubKeyTree(%%2); //"DBNewTest"
rkLocalM.Close();
RegistryKey rkSub = rkLocalM.CreateSubKey( strSubKey +"\"+%%2);
rkLocalM.Close();