当前位置:网站首页>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
边栏推荐
- 系统与软件安全研究(二)
- typescript字典的使用
- Reflect on the limitations of event bus and the design and implementation of communication mechanism in component development process
- Mobile game performance optimization
- c#读取INI文件和向ini文件写入数据
- Scrapy 修改爬虫结束时统计数据中的时间为当前系统时间
- SQL针对字符串型数字进行排序
- 根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
- Implementation of MySQL persistence
- Install and configure Taobao image NPM (cnpm)
猜你喜欢

SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)

对复杂字典Dictionary&lt;T1,T2&gt;排序问题

SAP PI/PO rfc2Soap 发布rfc接口为ws示例

C# 多个矩形围成的多边形标注位置的问题

js之排他思想及案例

Apache Hudi 如何加速传统的批处理模式?

ABAP 7.4 SQL Window Expression

Page dynamic display time (upgraded version)

Rethink | open the girl heart mode of station B and explore the design and implementation of APP skin changing mechanism

keytool: command not found
随机推荐
SQL针对字符串型数字进行排序
7. sub query
12. Constraints
移动布局(flex布局、视口标签)
4. Multi table query
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
ABAP 7.4 SQL Window Expression
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
H5 local storage data sessionstorage, localstorage
基于NLP的软件安全研究(一)
将指定路径下的所有SVG文件导出成PNG等格式的图片(缩略图或原图大小)
unity 屏幕自适应
MySQL storage engine
Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
踩坑日记:Unable to process Jar entry [module-info.class]
对复杂字典Dictionary&lt;T1,T2&gt;排序问题
10. Update operation
SAP PI/PO rfc2RESTful 發布rfc接口為RESTful示例(Proxy間接法)
快排的练习
游戏辅助脚本开发之旅