惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
L
LangChain Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
WordPress大学
WordPress大学
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
有赞技术团队
有赞技术团队
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog
博客园 - Franky

博客园 - 幸福★星

开心网外挂,开心网自动管理程序,现已经开发完成 Flex 图片 幻灯片效果初探 FDS.SWC 下载 解决使用FluorineFx实现Remoting通讯时 报 "Channel definition, mx.messaging.channels.RTMPChannel, can not be found" 错的问题 [转载]Flex 2.0 实现SWF全屏 - 幸福★星 [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (四) [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (三) [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (二) [原创]Flex 与 Asp.Net 通过 Remoting 方式进行通讯 (一) [原创]C#不调用API读写INI文件类 [原创]简单的XML配置文件读写类 VB 6.0 利用CopyMemory实现 指针功能 Sql Server 2000 中 将 0,1 字段,换成 是,否 的查询语句 [原创]C# 操作Excel的类 MSN病毒"性感相册"一个变种的手工杀毒方法 TFS 查看工作区,删除工作区,删除项目 开如使用TFS VS.NET 2005 SP1 安装注意 C# 系统热键类的修正
[原创]简单的读写注册表配置类
幸福★星 · 2007-09-14 · via 博客园 - 幸福★星

第三个读写配置类,使用的是注册表,由于以前没使用过注册表做为配置文件来读写,所以该类比较初级,只是按自己想法所写,有何不足请批评指教

http://xingfustar.cnblogs.com

/*----------------------------------------------------------------
 * 版权:
http://XingFuStar.cnblogs.com
 * 
 * 文件名: IniConfig
 * 文件功能描述: 读写注册表中的配置
 * 
 * 作者:XingFuStar
 * 日期:2007年9月14日
 * 
 * 当前版本:V1.0.0
 * 
 * 修改日期:
 * 修改内容:
 *---------------------------------------------------------------
*//*----------------------------------------------------------------
 * 
 * 默认注册表键为:HKEY_LOCAL_MACHINE\Software
 * 示意图如下:
 * 
 * HKEY_LOCAL_MACHINE          |   
 * -Software                          |   Key1   Value1
 * --程序项(SoftwareName)   |    
 * ---子项(Section)            |   KeyN   ValueN
 * 
 *---------------------------------------------------------------
*/using System;
using System.Collections.Generic;
using System.Text;using Microsoft.Win32;
using System.Diagnostics;namespace XingFuStudio.Config
{
    
class RegConfig
    {
        
private string softwareName;
        
private bool isConfig;
        RegistryKey registryKey;
/// <summary>
        
/// 构造函数
        
/// </summary>
        
/// <param name="softwareName">程序名称:对应注册表中Software项下的程序项</param>
        public RegConfig(string softwareName)
        {
            
//请不要删除以下信息
            
//版权:http://XingFuStar.cnblogs.com

            
this.SoftwareName = softwareName;
        }
/// <summary>
        
/// 程序名称:对应注册表中Software项下的程序项
        
/// </summary>
        public string SoftwareName
        {
            
set
            {
                softwareName 
= value;
                isConfig 
= OnSoftwareNameChange();
            }
        }
/// <summary>
        
/// 读取配置
        
/// </summary>
        
/// <param name="section">程序项下的子项</param>
        
/// <param name="key"></param>
        
/// <param name="value">返回的键值</param>
        
/// <returns>是否读取成功</returns>
        public bool ReadConfig(string section, string key, ref string value)
        {
            
bool isRead = false;
            
try
            {
                
if (isConfig)
                {
                    RegistryKey skey 
= this.registryKey.OpenSubKey(section);
                    
if (skey != null)
                    {
                        value 
= skey.GetValue(key).ToString();
                        isRead 
= true;
                    }
                }

            }

catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            
return isRead;
        }
/// <summary>
        
/// 写入配置
        
/// </summary>
        
/// <param name="section">程序项下的子项</param>
        
/// <param name="key"></param>
        
/// <param name="value">写入的键值</param>
        
/// <returns>是否写入成功</returns>
        public bool WriteConfig(string section, string key, string value)
        {
            
bool isWrite = false;
            
try
            {
                
if (isConfig)
                {
                    RegistryKey skey 
= this.registryKey.OpenSubKey(section, true);
                    
if (skey != null)
                    {
                        skey.SetValue(key, value);
                        isWrite 
= true;
                    }
                    
else    //如果不存在该键则创建
                    {
                        skey 
= this.registryKey.CreateSubKey(section);
                        skey.SetValue(key, value);
                        isWrite 
= true;
                    }
                }
            }
            
catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            
return isWrite;
        }
#region 私有方法
        
private bool OnSoftwareNameChange()
        {
            
bool isLoad = false;
            
try
            {
                
//打开该项
                registryKey = Registry.LocalMachine.OpenSubKey("Software\\" + softwareName, true);
                
if (registryKey == null)
                {
                    
//如果不存在则创建该项
                    registryKey = Registry.LocalMachine.CreateSubKey("Software\\" + softwareName);
                }
                isLoad 
= true;
            }
            
catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
            
return isLoad;
        }
        
#endregion
    }
}


http://xingfustar.cnblogs.com