C注册表操作大全.docx

上传人:b****4 文档编号:24349619 上传时间:2023-05-26 格式:DOCX 页数:15 大小:17.98KB
下载 相关 举报
C注册表操作大全.docx_第1页
第1页 / 共15页
C注册表操作大全.docx_第2页
第2页 / 共15页
C注册表操作大全.docx_第3页
第3页 / 共15页
C注册表操作大全.docx_第4页
第4页 / 共15页
C注册表操作大全.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

C注册表操作大全.docx

《C注册表操作大全.docx》由会员分享,可在线阅读,更多相关《C注册表操作大全.docx(15页珍藏版)》请在冰豆网上搜索。

C注册表操作大全.docx

C注册表操作大全

1.´ò¿ª¼ü

CStringStrKey(%%1);

HKEYm_hKey=%%2;

if(ERROR_SUCCESS==:

:

RegOpenKeyEx(m_hKey,StrKey,NULL,KEY_ALL_ACCESS,&m_hKey))

{

%%3

}

2.Ìí¼Ó¼ü

CStringStrKey(%%1);

HKEYhKey;

DWORDdwDisposition;

if(ERROR_SUCCESS==:

:

RegCreateKeyEx(m_hKey,(LPCTSTR)StrKey,0,NULL,

REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,&dwDisposition))

{

m_hKey=hKey;

if(dwDisposition==REG_CREATED_NEW_KEY)

{

%%2

}

elseif(dwDisposition==REG_OPENED_EXISTING_KEY)

{

%%3

}

}

3.ɾ³ý¼ü

CStringStrKey(%%1);

HKEYSrcKey=m_hKey;

charKeyName[256];

intnRes=0;

if(OpenKey(SrcKey,StrKey))

{

nRes=FirstEnumKey(KeyName);

while(nRes)

{

DeleteKey(KeyName);

nRes=NextEnumKey(KeyName);

}

}

if(:

:

RegDeleteKey(SrcKey,StrKey)==ERROR_SUCCESS)

{

%%2

}

4.ö¾ÙµÚÒ»¸ö¼ü

DWORDdwSize=255;

m_EnumLoop=0;

if(ERROR_SUCCESS==:

:

RegEnumKeyEx(m_hKey,m_EnumLoop,%%1,&dwSize,NULL,NULL,NULL,NULL))

{

%%2

}

5.ö¾ÙÏÂÒ»¸ö¼ü

DWORDdwSize=255;

m_EnumLoop++;

if(ERROR_SUCCESS==:

:

RegEnumKeyEx(m_hKey,m_EnumLoop,%%1,&dwSize,NULL,NULL,NULL,NULL))

{

%%2

}

6.»ñÈ¡DWORDÖµ

CStringStrChildKey(%%1);

DWORD%%1;

DWORDdwSize=255,dwType=REG_DWORD;

if(ERROR_SUCCESS==:

:

RegQueryValueEx(m_hKey,StrChildKey,0,&dwType,(BYTE*)(&%%2),&dwSize))

{

%%2

}

7.»ñÈ¡¶þ½øÖÆÖµ

CStringStrChildKey(%%1);

DWORD%%1;

DWORDdwSize=255,dwType=REG_BINARY;

if(ERROR_SUCCESS==:

:

RegQueryValueEx(m_hKey,StrChildKey,0,&dwType,(BYTE*)(&%%2),&dwSize))

{

%%2

}

8.¶ÁÈ¡×Ö·û´®Öµ

CStringStrChildKey(%%1);

CString%%2;

DWORDdwSize=255,dwType=REG_SZ;

charString[256];

if(ERROR_SUCCESS==:

:

RegQueryValueEx(m_hKey,StrChildKey,0,&dwType,(BYTE*)String,&dwSize))

%%2=CString(String);

9.дÈë×Ö·û´®Öµ

CStringStrChildKey(%%1);

CStringValue;

CString%%2;

if(ERROR_SUCCESS==:

:

RegSetValueEx(m_hKey,(LPCTSTR)StrChildKey,0,REG_SZ,(BYTE*)(LPCSTR)Value,strlen(Value)+1))

%%2=CString(Value);

10.дÈë¶þ½øÖÆÖµ

CStringStrChildKey(%%1);

constchar*%%2;

if(ERROR_SUCCESS==:

:

RegSetValueEx(m_hKey,(LPCTSTR)StrChildKey,0,REG_BINARY,(BYTE*)%%2,strlen(Value)))

{

%%3

}

11.дÈëDWORDÖµ

CStringStrChildKey(%%1);

DWORD%%2;

if(ERROR_SUCCESS==:

:

RegSetValueEx(m_hKey,(LPCTSTR)StrChildKey,0,REG_DWORD,(BYTE*)&%%2,sizeof(Value)))

{

%%3

}

12.ÉèÖÃDWORDÖµ

BOOLCRegEdit:

:

SetDwordValue(HKEYRoot,LPCTSTRStrKey,LPCTSTRStrChildKey,DWORDValue)

m_hKey=m_RootKey=Root;

if(CreateKey(StrKey))

{

if(WriteDword(StrChildKey,Value))

{

%%2

}

13.ɾ³ýÖµ

if(ERROR_SUCCESS==RegDeleteValue(m_hKey,%%1))

{

%%2

}

14.¹Ø±Õ¼ü

if(m_hKey!

=NULL)

:

:

RegCloseKey(m_hKey);

15.ÁгöÒ»¸ö¼üÏÂËùÓеÄ×Ó¼ü

//#defineMAX_KEY_LENGTH255

TCHARsubKey[MAX_KEY_LENGTH];

DWORDnumSubKey=0;

DWORDi;

DWORDsizeSubKey;

TCHARsubKey[MAX_KEY_LENGTH];

RegQueryInfoKey(m_hKey,NULL,NULL,NULL,&numSubKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL);

if(numSubKey)

{

for(i=0;i

{

subKey[0]='\0';

sizeSubKey=MAX_KEY_LENGTH;

RegEnumKeyEx(m_hKey,i,subKey,&sizeSubKey,NULL,NULL,NULL,NULL);

CString%%1=CString(subKey);

}

}

16.ÁгöÒ»¸ö¼üÏÂËùÓеÄÖµ

//#defineMAX_KEY_LENGTH255

//#defineMAX_VALUE_NAME16383

TCHARachKey[MAX_KEY_LENGTH];

DWORDcbName;

TCHARachClass[MAX_PATH]=TEXT("");

DWORDcchClassName=MAX_PATH;

DWORDcSubKeys=0;

DWORDcbMaxSubKey;

DWORDcchMaxClass;

DWORDcValues;

DWORDcchMaxValue;

DWORDcbMaxValueData;

DWORDcbSecurityDescriptor;

FILETIMEftLastWriteTime;

DWORDi,retCode;

TCHARachValue[MAX_VALUE_NAME];

DWORDcchValue=MAX_VALUE_NAME;

retCode=RegQueryInfoKey;

(m_hKey,achClass,&cchClassName,NULL,&cSubKeys,&cbMaxSubKey,&cchMaxClass,&cValues,&cchMaxValue,&cbMaxValueData,&cbSecurityDesc

riptor,&ftLastWriteTime);

if(cValues)

{

for(i=0,retCode=ERROR_SUCCESS;i

{

cchValue=MAX_VALUE_NAME;

achValue[0]='\0';

retCode=RegEnumValue(m_hKey,i,achValue,&cchValue,NULL,NULL,NULL,NULL);

if(retCode==ERROR_SUCCESS){

CString%%1=CString(achValue);

%%2

}

}

}

17.ÁгöÒ»¸ö¼üÏÂËùÓеÄ×Ó¼üºÍÖµ

//#defineMAX_KEY_LENGTH255

//#defineMAX_VALUE_NAME16383

TCHARachKey[MAX_KEY_LENGTH];

DWORDcbName;

TCHARachClass[MAX_PATH]=TEXT("");

DWORDcchClassName=MAX_PATH;

DWORDcSubKeys=0;

DWORDcbMaxSubKey;

DWORDcchMaxClass;

DWORDcValues;

DWORDcchMaxValue;

DWORDcbMaxValueData;

DWORDcbSecurityDescriptor;

FILETIMEftLastWriteTime;

DWORDi,retCode;

TCHARachValue[MAX_VALUE_NAME];

DWORDcchValue=MAX_VALUE_NAME;

retCode=RegQueryInfoKey

(m_hKey,achClass,&cchClassName,NULL,&cSubKeys,&cbMaxSubKey,&cchMaxClass,&cValues,&cchMaxValue,&cbMaxValueData,&cbSecurityDesc

riptor,&ftLastWriteTime);

if(cSubKeys)

{

for(i=0;i

{

cbName=MAX_KEY_LENGTH;

retCode=RegEnumKeyEx(m_hKey,i,achKey,&cbName,NULL,NULL,NULL,&ftLastWriteTime);

if(retCode==ERROR_SUCCESS){

CString%%1=CString(achKey);

%%2

}

}

}

if(cValues)

{

for(i=0,retCode=ERROR_SUCCESS;i

{

cchValue=MAX_VALUE_NAME;

achValue[0]='\0';

retCode=RegEnumValue(m_hKey,i,achValue,&cchValue,NULL,NULL,NULL,NULL);

if(retCode==ERROR_SUCCESS){

CString%%3=CString(achValue);

%%4

}

}

}

18.ö¾ÙËùÓеÄ×Ó¼üºÍÖµ

voidRegSearch(HKEYhKey,TCHARrootKey[],CStringpath)

{

DWORDnumSubKey=0;//´æ·Å×Ó¼üµÄÏîÊý

DWORDi;//¼ÆÊý

DWORDsizeSubKey;//×Ó¼ü´óС

TCHARsubKey[MAX_KEY_LENGTH];//×Ó¼üÃû

/*´ò¿ªhKeyÖеÄrootKey,hKeyÄ˼̳еݹéµ÷ÓÃÕßÖ®hKey,rootKeyÄ˵ݹéµ÷ÓÃÕßÖ®subKey*/

RegOpenKeyEx(hKey,//Óû¿ªÖ®¼ü±ú

rootKey,//Óû¿ªÖ®¸ù¼üÃû

0,//±£ÁôÖµ£¬Ç¿ÖÆ0

KEY_READ,//ȨÏÞ

&hKey);//´ò¿ª×Ó¼üºó£¬·µ»Ø¼ü±ú

/*Ê×ÏȲ鵱ǰ¼üϵÄÖµÃÇ(±íÃ÷ÊǸ´Êý¹þ)ÊÇ·ñÓзûºÏÌõ¼þµÄ*/

if(RegQueryValueEx(hKey,//Óû¿ªÖ®¼ü±ú

m_content,//Óû²éѯµÄÖµ

NULL,

NULL,

NULL,

NULL)==ERROR_SUCCESS)

{

findFlag=1;//ÔڸüüÏ£¬Ö±½Ó²éÕҳɹ¦

m_result=path;

return;//Ìø³öµÝ¹é

}

/*ûÓв鵽£¬Ôò½øÈë×Ó¼ü²éѯ*/

else

{

/*Ê×ÏȲéµÃµ±Ç°¼üϵÄ×Ó¼üÏîÊý*/

RegQueryInfoKey(hKey,

NULL,

NULL,

NULL,

&numSubKey,//²éµÃ×Ó¼üµÄÏîÊý

NULL,

NULL,

NULL,

NULL,

NULL,

NULL,

NULL);

/*Èç¹û×Ó¼üÊý²»Îª0£¬±éÀú×Ó¼ü*/

if(numSubKey)

{

for(i=0;i

{

subKey[0]='\0';//¸ÃÁ½ÐкÜÖØÒª£¬±£Ö¤ÁËÿ´ÎÑ»·µÄ³õʼ

sizeSubKey=MAX_KEY_LENGTH;//µÚÒ»ÐÐÇå¿Õ×Ó¼ü£¬µÚ¶þÐи³»º³åÇø´óС

RegEnumKeyEx(hKey,//¼ü±ú

i,//×Ó¼üÐòºÅ

subKey,//´æÈë×Ó¼üÃû

&sizeSubKey,//Ö¸Ã÷»º³åÇø´óС

NULL,

NULL,

NULL,

NULL);

RegSearch(hKey,subKey,path+subKey+"\\");//µÝ¹é

}

}

}

RegCloseKey(hKey);//ÊÕβ¹¤×÷ÊÇÒ»¶¨Òª×öµÄ£¬·ñÔò»úÆ÷»áÒì³£µÄÂý

}

RegSearch(HKEY_USERS,"","");m_result="HKEY_USERS\\"+m_result;break;

RegSearch(HKEY_LOCAL_MACHINE,"","");m_result="HKEY_LOCAL_MACHINE\\"+m_result;break;

19.Ä£ºýËÑË÷ËùÓеÄ×Ó¼üºÍÖµ£¬²éÕÒÌض¨×Ö·û´®²¢É¾³ý

voidRegSearch(HKEYhKey,TCHARrootKey[],CStringpath)

{

DWORDnumSubKey=0;//´æ·Å×Ó¼üµÄÏîÊý

DWORDi;//¼ÆÊý

DWORDsizeSubKey;//×Ó¼ü´óС

TCHARsubKey[MAX_KEY_LENGTH];//×Ó¼üÃû

/*´ò¿ªhKeyÖеÄrootKey,hKeyÄ˼̳еݹéµ÷ÓÃÕßÖ®hKey,rootKeyÄ˵ݹéµ÷ÓÃÕßÖ®subKey*/

RegOpenKeyEx(hKey,//Óû¿ªÖ®¼ü±ú

rootKey,//Óû¿ªÖ®¸ù¼üÃû

0,//±£ÁôÖµ£¬Ç¿ÖÆ0

KEY_READ,//ȨÏÞ

&hKey);//´ò¿ª×Ó¼üºó£¬·µ»Ø¼ü±ú

/*Ê×ÏȲ鵱ǰ¼üϵÄÖµÃÇ(±íÃ÷ÊǸ´Êý¹þ)ÊÇ·ñÓзûºÏÌõ¼þµÄ*/

if(RegQueryValueEx(hKey,//Óû¿ªÖ®¼ü±ú

m_content,//Óû²éѯµÄÖµ

NULL,

NULL,

NULL,

NULL)==ERROR_SUCCESS)

{

findFlag=1;//ÔڸüüÏ£¬Ö±½Ó²éÕҳɹ¦

m_result=path;

return;//Ìø³öµÝ¹é

}

/*ûÓв鵽£¬Ôò½øÈë×Ó¼ü²éѯ*/

else

{

/*Ê×ÏȲéµÃµ±Ç°¼üϵÄ×Ó¼üÏîÊý*/

RegQueryInfoKey(hKey,

NULL,

NULL,

NULL,

&numSubKey,//²éµÃ×Ó¼üµÄÏîÊý

NULL,

NULL,

NULL,

NULL,

NULL,

NULL,

NULL);

/*Èç¹û×Ó¼üÊý²»Îª0£¬±éÀú×Ó¼ü*/

if(numSubKey)

{

for(i=0;i

{

subKey[0]='\0';//¸ÃÁ½ÐкÜÖØÒª£¬±£Ö¤ÁËÿ´ÎÑ»·µÄ³õʼ

sizeSubKey=MAX_KEY_LENGTH;//µÚÒ»ÐÐÇå¿Õ×Ó¼ü£¬µÚ¶þÐи³»º³åÇø´óС

RegEnumKeyEx(hKey,//¼ü±ú

i,//×Ó¼üÐòºÅ

subKey,//´æÈë×Ó¼üÃû

&sizeSubKey,//Ö¸Ã÷»º³åÇø´óС

NULL,

NULL,

NULL,

NULL);

RegSearch(hKey,subKey,path+subKey+"\\");//µÝ¹é

}

}

}

RegCloseKey(hKey);//ÊÕβ¹¤×÷ÊÇÒ»¶¨Òª×öµÄ£¬·ñÔò»úÆ÷»áÒì³£µÄÂý

}

RegSearch(HKEY_USERS,"","");m_result="HKEY_USERS\\"+m_result;break;

RegSearch(HKEY_LOCAL_MACHINE,"","");m_result="HKEY_LOCAL_MACHINE\\"+m_result;break;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1