当前位置:网站首页>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
边栏推荐
猜你喜欢

SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)

Super classic & Programming Guide (red and blue book) - Reading Notes

SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)

js之节点操作,为什么要学习节点操作

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

SAP PI/PO Soap2Proxy 消费外部ws示例

js之预解析

FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning

SAP TRANSLATE使用数据对象掩码示例

SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)
随机推荐
MySQL index
js之预解析
2. Restricted query
7. sub query
基于NLP的软件安全研究(一)
SAP ECC连接SAP PI系统配置
Date object (JS built-in object)
Use of typescript dictionary
TimelineWindow
[Ted series] how does a habit change my life
NodeJS(四) 字符读取
Authorization server (simple construction of authorization server)
对js中argumens的简单理解
Nacos / sentinel gateway current limiting and grouping (code)
Game assisted script development journey
SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)
UnityShader基础
ABAP CDS VIEW WITH ASSOCIATION示例
[self motivation series] what really hinders you?
Moment. Format of format method function in JS