经常操作注册表,然后得到一份操作注册表函数实现。这里备份下。

#ifndef _REGEDIT_H
#define _REGEDIT_H int RegRead_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,TCHAR *Content, DWORD nLength);
int RegRead_D (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,BYTE *Content, DWORD nLength);
int RegSetValue_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S);
int RegSetValue_D (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S);
int RegSetValue_B (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,BYTE ReSetContent_B[256]);
int RegDeleteKey (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReKeyName);
int RegDeleteValue (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName); #endif
#include "StdAfx.h"
#include "regedit.h" int RegRead_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,TCHAR *Content, DWORD nLength)
{
HKEY hKey;
int i=0; //操作结果:0==succeed
DWORD dwType = REG_SZ;
DWORD dwLength = nLength;
if(RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_READ,&hKey)==ERROR_SUCCESS)
{
if(RegQueryValueEx(hKey,ReValueName,NULL,&dwType,(LPBYTE)Content,&dwLength)!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
} int RegRead_D (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,BYTE *Content, DWORD nLength)
{
HKEY hKey;
int i=0; //操作结果:0==succeed
DWORD dwType = REG_DWORD;
DWORD dwLength = nLength;
if(RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_READ,&hKey)==ERROR_SUCCESS)
{
if(RegQueryValueEx(hKey,ReValueName,NULL,&dwType,(LPBYTE)Content,&dwLength)!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
} int RegSetValue_S (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_S)
{
int i=0; //操作结果:0==succeed
HKEY hKey;
if(RegCreateKeyEx(ReRootKey,ReSubKey,0,NULL,NULL,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
int nLen = _tcslen((TCHAR*)ReSetContent_S);
if(RegSetValueEx(hKey,ReValueName,NULL,REG_SZ,ReSetContent_S,nLen*sizeof(TCHAR)+1)!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
} int RegSetValue_D (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,LPBYTE ReSetContent_D)
{
int i=0; //操作结果:0==succeed
HKEY hKey;
if(RegCreateKeyEx(ReRootKey,ReSubKey,0,NULL,NULL,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
if(RegSetValueEx(hKey,ReValueName,NULL,REG_DWORD,(LPBYTE)ReSetContent_D,sizeof(DWORD))!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
} int RegSetValue_B (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName,BYTE ReSetContent_B[256])
{
int i=0; //操作结果:0==succeed
HKEY hKey;
if(RegCreateKeyEx(ReRootKey,ReSubKey,0,NULL,NULL,KEY_ALL_ACCESS,NULL,&hKey,NULL)==ERROR_SUCCESS)
{
if(RegSetValueEx(hKey,ReValueName,NULL,REG_BINARY,(LPBYTE)ReSetContent_B,sizeof(DWORD))!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
} int RegDeleteKey (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReKeyName)
{
int i=0; //操作结果:0==succeed
HKEY hKey;
if((RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_WRITE,&hKey))==ERROR_SUCCESS)
{
if((RegDeleteKey(hKey,ReKeyName))!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
} int RegDeleteValue (struct HKEY__*ReRootKey,TCHAR *ReSubKey,TCHAR *ReValueName)
{
int i=0; //操作结果:0==succeed
HKEY hKey;
if(RegOpenKeyEx(ReRootKey,ReSubKey,0,KEY_WRITE,&hKey)==ERROR_SUCCESS)
{
if(RegDeleteValue(hKey,ReValueName)!=ERROR_SUCCESS)
{
i=1;
}
RegCloseKey(hKey);
}
else
{
i=1;
}
return i;
}

Windows 注册表操作的更多相关文章

  1. 《天书夜读:从汇编语言到windows内核编程》八 文件操作与注册表操作

    1)Windows运用程序的文件与注册表操作进入R0层之后,都有对应的内核函数实现.在windows内核中,无论打开的是文件.注册表或者设备,都需要使用InitializeObjectAttribut ...

  2. winreg操作windows注册表详解示例

    #coding:utf-8 #=====================================================================#=====本程序演示了WINR ...

  3. 使用Java修改Windows注册表

    使用Java修改Windows注册表,使用最基本的就是cmd命令. 事例和运行结果如下所示: package day01; import java.io.IOException; /* 1,reg a ...

  4. Java 修改Windows注册表,以实现开机自启动应用程序。

    使用Java修改Windows注册表,使用最基本的就是cmd命令. 事例和运行结果如下所示: package day01; import java.io.IOException; /* 1,reg a ...

  5. delphi 注册表操作(读取、添加、删除、修改)完全手册

    DELPHI VS PASCAL(87)  32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...

  6. CRegKey 注册表操作

    CRegKey 注册表操作 标签: accessnulluserpathbyteie 2011-11-03 13:55 3477人阅读 评论(0) 收藏 举报  分类: win32(7)  1.简介 ...

  7. Windows注册表的基本知识及应用

    转帖:Windows注册表的基本知识及应用 2009-12-23 11:30:56 分类: Windows注册表的基本知识及应用  一.注册表的重要性 在DOS年代,对计算机的内存管理及系统配置主要通 ...

  8. Delphi的注册表操作

    转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息.     一.创 ...

  9. 10#Windows注册表的那些事儿

    引言 用了多年的Windows系统,其实并没有对Windows系统进行过深入的了解,也正是由于Windows系统不用深入了解就可以简单上手所以才有这么多人去使用.笔者是做软件开发的,使用的基本都是Wi ...

随机推荐

  1. Java线程的相关方法

    ~ start()  启动线程方法 ~ run()  调用start()方法时,真正执行的就是该方法的方法体 ~ sleep()  让当前线程睡眠,睡眠到期自动苏醒,并进入可运行状态,而不是运行状态 ...

  2. 《火球——UML大战需求分析》(第1章 大话UML)——1.4 如何学好UML?

    说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...

  3. php中运用GD库实现简单验证码

    昨天学习了运用php的GD库进行验证码的实现. 首先可以用phpinfo()函数看一下GD库有没有安装,我用的wampserver是自动给安装的. 主要的步骤是: 1.生成验证码图片 2.随机生成字符 ...

  4. sql 处理以字符隔开的字符串(类似split)

    sql 处理以字符隔开的字符串(类似split)的处理方法. CREATE PROCEDURE dbo.Vip_SendMails @userids varchar(MAX), ), ), @c va ...

  5. 配置WifiConfiguration

    public WifiConfiguration CreateWifiInfo(String SSID, String Password, int Type) { WifiConfiguration  ...

  6. Virtualbox安装增强工具失败

    在安装Virtualbox增强工具安装时出现unable to find the sources of your current Linux kernel,安装失败,导致主机与虚拟机之间不能共享文件夹 ...

  7. table的border-collapse属性与border-spacing属性

    table border-collapse:collapse; 表示边框合并在一起. border-collapse:separate;表示边框之间的间距,间距的大小用border-spacing:p ...

  8. animation-timing-function中的cubic-bezier(n,n,n,n)

    cubic-bezier即为贝兹曲线中的绘制方法.图上有四点,P0-3,其中P0.P3是默认的点,对应了[0,0], [1,1].而剩下的P1.P2两点则是我们通过cubic-bezier()自定义的 ...

  9. -webkit-appearance改变任何元素的浏览器默认风格

    前段时间,公司有个紧急发布会,需要在移动端做一个邀请函的页面.但是在实现下拉框的时候,IOS和安卓展示的效果总是不一样.经过我一番查找,偶然间发现了-webkit-appearance这个样式属性.后 ...

  10. location.href的用法

    *.location.href 用法: top.location.href=”url”          在顶层页面打开url(跳出框架) self.location.href=”url”       ...