We help IT Professionals succeed at work.

RegCreateKeyEx fails with error code 87

CSecurity
CSecurity asked
on
5,040 Views
Last Modified: 2013-12-14
Hi

I have following code in MFC dialog:

char method[20];
strcpy(method, "Test");
HKEY reg;
DWORD dwDisp = 0;
LPDWORD lpdwDisp = &dwDisp;
CString regKey = "Sofware\\Testing";
int ret = RegCreateKeyEx(HKEY_LOCAL_MACHINE, regKey, 0, NULL,  REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &reg, lpdwDisp);
RegSetValueEx(reg, "TestMethod", 0, 1, (PBYTE)&method, sizeof(method));
RegCloseKey(reg);


I want to get it working in XP and Vista... What's wrong in above code? I always get 87 (INVALID_PARAMETER) in ret variable.
Comment
Watch Question

Commented:
I think that regkey should not contain two backslashes. What programming language are you using?

Commented:
Try to open HKLM and Software and then create the key "Testing". Also, will be nice to remove this REG_OPTION_NON_VOLATILE. At least for a beginning, to get the code work.

Commented:
:)
I'd say that the programming language was using me a half of a day today.

Author

Commented:
Why and how to open HKLM Software first? Also do you know better parameter for REG_OPTION_NON_VIOLATILE? I added that to make my program working on Vista also
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.