当前位置:网站首页>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
边栏推荐
- c#读取INI文件和向ini文件写入数据
- SVG中年月日相关的表达式
- Game assisted script development journey
- 解决在docker中部署mysql8, 密码正确但无法登陆MySQL问题
- 'NPM' is not an internal or external command, nor is it a runnable program or batch file
- js之节点操作,为什么要学习节点操作
- Super classic & Programming Guide (red and blue book) - Reading Notes
- 踩坑日记:Unable to process Jar entry [module-info.class]
- js之预解析
- FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
猜你喜欢

超级宝典&编程指南(红蓝宝书)-读书笔记

Simple random roll call lottery (written under JS)

SVG中Path Data数据简化及文件夹所有文件批量导出为图片

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

Implementation of MySQL persistence

SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)

利用Lambda表达式解决c#文件名排序问题(是100大还是11大的问题)

MySQL index

Redis connection error err auth < password > called without any password configured for the default user

SAP 导出Excel文件打开显示:“xxx“的文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?
随机推荐
Dropping Pixels for Adversarial Robustness
Rethink | open the girl heart mode of station B and explore the design and implementation of APP skin changing mechanism
SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
学会使用搜索引擎
SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
将单行文字自动适应到目标矩形框内
electron-builder打包报错:proxyconnect tcp: dial tcp :0: connectex
移动端布局(3D转换、动画)
对js中argumens的简单理解
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
Daily question | fear dominated by reverse linked list
5. Sql99 standard: internal connection and external connection
基于NLP的软件安全研究(一)
SAP RFC_CVI_EI_INBOUND_MAIN BP主数据创建示例(仅演示客户)
Design optimization of MySQL database
SAP PI / Po rfc2restful Publishing RFC interface as restful examples (proxy indirect)
C#使用拉依达准则(3σ准则)剔除异常数据(.Net剔除一组数据中的奇异值)
MySQL storage engine
给定区段范围内字符串自生成代码