当前位置:网站首页>C reads the registry
C reads the registry
2022-04-23 07:47:00 【youth who behaves like an adult】
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Win32;
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(" Here is the information read "+"<br/>");
ReadRegedit();
Response.Write("<br/>");
Response.Write(" The information to be written here swort/swort-test" + "<br/>");
WriteRegedit();
Response.Write(" End of write " + "<br/>");
Response.Write(" Check whether it exists " + "<br/>");
ExistsRegedit();
Response.Write(" End of view " + "<br/>");
Response.Write(" Delete " + "<br/>");
DeleteRegedit();
Response.Write(" Delete end " + "<br/>");
Response.Write(" Check whether it exists " + "<br/>");
ExistsRegedit();
Response.Write(" End of view " + "<br/>");
}
/// <summary>
/// Reading of registry
/// </summary>
/// <returns></returns>
public void ReadRegedit()
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders");
foreach (string b in shell.GetValueNames())// Here we use shell.GetValueNames() No shell.GetSubKeyNames()
{
Response.Write( b+" "+ shell.GetValue(b).ToString());
Response.Write("<br/>");
}
}
/// <summary>
/// Write to the registry
/// </summary>
/// <returns></returns>
public bool WriteRegedit()
{
try
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders", true);// It has to be added here true Is to get write permission
RegistryKey key = shell.CreateSubKey("swort");// establish swort Catalog
key.SetValue("swort", "test");
// stay swort Create a write directory swort test
Response.Write(" Write successfully !!!!!!!!!");
return true;
}
catch
{
return false;
}
}
/// <summary>
/// Deletion of registry
/// </summary>
/// <returns></returns>
public bool DeleteRegedit()
{
try
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders",true);
RegistryKey swort = shell.OpenSubKey("swort",true);// It has to be added here true Is to get write permission
swort.DeleteValue("swort");// Delete swort Value This key value is deleted together There's one left
shell.DeleteSubKey("swort",false);// Delete swort This directory To delete this directory Must have permission
Response.Write(" Delete successful !!!!!!!!!");
return true;
}
catch
{
return false;
}
return true;
}
/// <summary>
/// Query whether a key value exists
/// </summary>
/// <returns></returns>
public bool ExistsRegedit()
{
RegistryKey rk = Registry.CurrentUser;
RegistryKey softWare = rk.OpenSubKey("Software");
RegistryKey microsoft = softWare.OpenSubKey("Microsoft");
RegistryKey windows = microsoft.OpenSubKey("Windows");
RegistryKey current = windows.OpenSubKey("CurrentVersion");
RegistryKey explorer = current.OpenSubKey("Explorer");
RegistryKey shell = explorer.OpenSubKey(@"Shell Folders");
if (shell.SubKeyCount != 0)
{
RegistryKey swort = shell.OpenSubKey("swort");
foreach (string b in swort.GetValueNames())
{
if (b == "swort")
{
Response.Write(" There is this key !");
return true;
}
}
Response.Write(" There is no such key !");
return false;
}
else
{ Response.Write(" There is no such key !");
return false;
}
}
}
版权声明
本文为[youth who behaves like an adult]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230626191446.html
边栏推荐
- Authorization+Token+JWT
- 颜色转换公式大全及转换表格(31种)
- MySQL storage engine
- Design optimization of MySQL database
- 超级宝典&编程指南(红蓝宝书)-读书笔记
- Simple random roll call lottery (written under JS)
- electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
- Dropping Pixels for Adversarial Robustness
- js之什么是事件?事件三要素以及操作元素
- Processing of common dependency module
猜你喜欢
SAP PI/PO Soap2Proxy 消费外部ws示例
SQL针对字符串型数字进行排序
【NLP笔记】CRF原理初探
js之DOM事件
Redis connection error err auth < password > called without any password configured for the default user
SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。
King glory - unity learning journey
MySQL index
The page displays the current time in real time
ABAP 实现发布RESTful服务供外部调用示例
随机推荐
系统与软件安全研究(一)
Understanding of STL container
8. Paging query
3. Sort statement
根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
Custom time format (yyyy-mm-dd HH: mm: SS week x)
C# 多个矩形围成的多边形标注位置的问题
6. Aggregation function and grouping statistics
Thorough inquiry -- understanding and analysis of cocos2d source code
BTree、B+Tree和HASH索引
MySQL index
NodeJS(六) 子进程操作
js中对象的三种创建方式
typescript字典的使用
Window10版MySQL设置远程访问权限后不起效果
Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
url转成对象
SAP PI/PO登录使用及基本功能简介
js之自定义属性以及H5中如何判断自定义属性
unity UGUI判断点击在UI上和3D物体上的解决方案