. NET technology exchange group 199281001. welcome to join.
Using System; using System. collections. generic; using System. linq; using System. runtime. remoting. metadata. w3cXsd2001; using System. security. permissions; using System. text; using Microsoft. win32; // registry auxiliary class Author: BingBingpublic static class Regedit {// custom node name public static string NodeName = "XX "; // SOFTWARE node public static string SoftWare = "SOFTWARE "; /// <summary> /// read the registry value of the specified name /// </summary> /// <para M name = "key"> key of the registry value </param> // <returns> </returns> public static string GetValue (string key) {using (var aimdir = Load (SoftWare) {using (var child = aimdir. openSubKey (NodeName) {if (child = null) return null; var registData = child. getValue (key); return registData = null? Null: registData. toString ();}}} /// <summary> /// write data in the Registry /// </summary> /// <param name = "key"> key of the registry value </param>/ // <param name = "tovalue"> value </param> public static void AddValue (string key, string value) {using (var aimdir = Load (SoftWare) {using (var child = aimdir. openSubKey (NodeName, true) {if (child = null) return; if (ExistsValue (key, NodeName) return; child. setValue (key, value );}}} /// <Summary> /// Delete the registry key specified in the Registry /// </summary> /// <param name = "key"> key in the registry value </param> public static void DeleteValue (string key) {using (var aimdir = Load (SoftWare) {if (! ExistsValue (key, NodeName) return; using (var child = aimdir. OpenSubKey (NodeName, true) {if (child! = Null) {child. deleteValue (key );}}}} /// <summary> /// Load /// </summary> /// <returns> </returns> public static RegistryKey Load (string rootName) {var software = Registry. currentUser; return software. openSubKey (rootName, RegistryKeyPermissionCheck. readWriteSubTree, System. security. accessControl. registryRights. fullControl) ;}/// <summary> /// determine whether the specified registry key exists /// </summary> /// <param name = "node Name "> Name of the node on the left of the registry </param> // <returns> </returns> public static bool Exists (string nodeName) {var exit = false; using (var aimdir = Load (SoftWare) {var subkeyNames = aimdir. getSubKeyNames (); if (subkeyNames. any (keyName => keyName = nodeName) {exit = true ;}} return exit ;} /// <summary> /// determine whether the specified registry key exists /// </summary> /// <param name = "nodeName"> nodes on the left of the registry </param> /// <param name = "rootName"> parent node name </Param> // <returns> </returns> public static bool ExistsValue (string key, string rootName) {var exit = false; using (var aimdir = Load (SoftWare) {using (var child = aimdir. openSubKey (NodeName, true) {if (child = null) return exit; var subkeyNames = child. getValueNames (); if (subkeyNames. any (keyName => keyName = key) {exit = true ;}}return exit ;}/// <summary> /// create /// </summary> /// <Param name = "name"> node name on the left </param> public static void Create (string nodeName) {using (var software = Load (SoftWare )) {if (! Exists (nodeName) {software. createSubKey (nodeName );}}} /// <summary> /// start with windows /// </summary> /// <param name = "path"> absolute path of the program to be started </param> public static void AutoRun (string path) {using (var autorun = Load (SoftWare + @ "\ Microsoft \ Windows \ CurrentVersion \ Run") {autorun. setValue ("xxw.run", path );}} /// <summary> /// start with windows /// </summary> /// <param name = "path"> absolute path of the program to be started </param> public static void RemoveAutoRun () {using (var autorun = Load (SoftWare + @ "\ Microsoft \ Windows \ CurrentVersion \ Run") {if (autorun. getValue ("xxw.run") = null) return; autorun. deleteValue ("xxw.run ");}}}