简体   繁体   中英

How to set value Name and Value data to Newly created registry , MFC

I have gone through several post from stackoverflow.com and successfully create Registry key, But what i want is when i create registry at the same time create a Value Name and Value data with default data. What i will achieve from doing this is, I have application which requires registration when first time it is executed. So next time when the application is launched it should check the required registry status and skip those registration steps. When i have created new key i have Default value name and no data in it.

I want one more Value of type string and default value . How can i do it.. Please Help me.....

you may want to create a function that tries to open a key and if it does not find it then it creates it and assigns a default value to it.

You may find useful the following registry functions from winreg.h

The algorithm would have the following steps:

try to open a key, if does not exist create it

if (ERROR_SUCCESS != RegOpenKeyEx(key, KeyPath, 0, KEY_ALL_ACCESS, &hk) 
    RegCreateKey(key, KeyPath, &hk); //if key does not exist create it

Read the value from reg key:

RegQueryValueEx(hk, pValueName, 0, &DataType,(LPBYTE) pValue, &DataSize);

...and if none found (returns !=ERROR_SUCCESS), assign a value to a key:

RegSetValueEx(hk, pValueName, 0, REG_DWORD, (LPBYTE)pValue, DataSize);

close reg key:

RegCloseKey(hk);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM