Windows API experience and summary of registry operations

Source: Internet
Author: User

This article mainly introduces the Windows API on the operation of the Registry experience and summary, this article explains the reading of the registry commonly used functions and a registry operation instance, the need for friends can refer to the

Reading functions commonly used in the registry

RegOpenKeyEx is used to open a key

RegSetValueEx is used to set the key value of a key

RegQueryValueEx the value used to read a key

RegCloseKey is used to turn off Regopen open keys

RegQueryValueEx usually uses two times to read the key value, read only the key size for the first time, then allocate the memory, and then use the RegQueryValueEx to read the key value to the buffer.

Here is an example of reading the path key value under Windows

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59-60 hkey HK   int result = RegOpenKeyEx (HKEY_LOCAL_MACHINE, _t ("Systemcontrol Set001controlsession managerenvironment "), NULL, Key_read, &HK);   if (result!= error_success) {if (result = = Error_file_not_found) {  MessageBox (g.hwnd,_t ("No such key in rego Penkeyex "), _t (" title "), mb_iconwarning); }   else   return; }   DWORD lsize;   result = RegQueryValueEx (HK, _t ("Path"), Null,null, NULL, &lsize);     If (result!= error_success) {if (result = = Error_file_not_found) {  MessageBox (g.hwnd,_t ("No such key In RegQueryValue "), _t (" title "), mb_iconwarning); else if (result = = Error_more_data) {MessageBox (g.hwnd,_t ("need more Buffer"), _t ("title"), Mb_iconwarniNG); else   return; } TCHAR *value = (TCHAR *) malloc (lsize * sizeof (TCHAR)); result = RegQueryValueEx (HK, _t ("Path"), Null,null, (LPBYTE) value, &lsize); If (result!= error_success) {if (result = = Error_file_not_found) {  MessageBox (g.hwnd,_t ("No such key in Regqueryval UE "), _t (" title "), mb_iconwarning); else if (result = = Error_more_data) {MessageBox (g.hwnd,_t ("need more Buffer"), _t ("title"), mb_iconwarning); else   ; Return } setwindowtext (G.hwndedit,value); Free (value); RegCloseKey (HK);

Novice FAQ

The RegSetValueEx runtime failed with the return code of 5,

Workaround: This situation is due to the lack of access to the registry, the meaning of access denied, so pay attention to see if the permissions are not enough, if you change to

Key_all_access is no problem, such as reading and writing permissions can be.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.