Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
RegistryUtil.cs
Package: ProgressBar_src.rar [view]
Upload User: nnpulika
Upload Date: 2013-02-15
Package Size: 597k
Code Size: 2k
Category:
StatusBar
Development Platform:
C#
- using System;
- using Microsoft.Win32;
- namespace UtilityLibrary.Win32
- {
- /// <summary>
- /// Summary description for Registry.
- /// </summary>
- public class RegistryUtil
- {
- #region Constructors
- // No need to constructo this object
- private RegistryUtil()
- {
- }
- #endregion
- #region Implementation
- static public void WriteToRegistry(RegistryKey RegHive, string RegPath, string KeyName, string KeyValue)
- {
- // Split the registry path
- string[] regStrings;
- regStrings = RegPath.Split('\');
- // First item of array will be the base key, so be carefull iterating below
- RegistryKey[] RegKey = new RegistryKey[regStrings.Length + 1];
- RegKey[0] = RegHive;
- for( int i = 0; i < regStrings.Length; i++ )
- {
- RegKey[i + 1] = RegKey[i].OpenSubKey(regStrings[i], true);
- // If key does not exist, create it
- if (RegKey[i + 1] == null)
- {
- RegKey[i + 1] = RegKey[i].CreateSubKey(regStrings[i]);
- }
- }
- // Write the value to the registry
- try
- {
- RegKey[regStrings.Length].SetValue(KeyName, KeyValue);
- }
- catch (System.NullReferenceException)
- {
- throw(new Exception("Null Reference"));
- }
- catch (System.UnauthorizedAccessException)
- {
- throw(new Exception("Unauthorized Access"));
- }
- }
- static public string ReadFromRegistry(RegistryKey RegHive, string RegPath, string KeyName, string DefaultValue)
- {
- string[] regStrings;
- string result = "";
- regStrings = RegPath.Split('\');
- //First item of array will be the base key, so be carefull iterating below
- RegistryKey[] RegKey = new RegistryKey[regStrings.Length + 1];
- RegKey[0] = RegHive;
- for( int i = 0; i < regStrings.Length; i++ )
- {
- RegKey[i + 1] = RegKey[i].OpenSubKey(regStrings[i]);
- if (i == regStrings.Length - 1 )
- {
- result = (string)RegKey[i + 1].GetValue(KeyName, DefaultValue);
- }
- }
- return result;
- }
- #endregion
- }
- }