   c++/win32, RegCreateKeyEx fails
  i am trying to create a registry key for my application to run at startup andi have the following code:if(RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, NULL, 0, 0, NULL, &hkey, &dwDisposition) ==ERROR_SUCCESS){ dwType = REG_SZ; strcpy(buf,"hello world"); dwSize = (strlen(buf) + 1) * sizeof(char); RegSetValueEx(hkey,"Dummy Name", 0, dwType,(PBYTE)&buf, dwSize); RegCloseKey(hkey);}where `buf` is global char [64] (source: MSDN) I am using:Visual c++ 2005, windows XP professionalI get no compiler errors and the code is not working.Does anyone have any idea why??thanks , Makaan   
  Define "is not working". What does your debugger tell you? Is RegCreateKeyEx() failing? If so, with what error code?   ;  If RegCreateKeyEx is actually failing, chances are it is a permissions issue. Double check that your program has permission to be writing to that registry key, and elevate to Administrator privileges if necessary.   ;  Hmm, isn't RegCreateKeyEx for creating the key?It surely already exists and I don't know what RegCreateKeyEx does in the case where it already exists, but I suspect that it's failing.....Try RegOpenKeyEx instead.   ;  Thanks for the replies;The functions RegCreateKeyEx returns number 5 and the key is absolutely new;i found on MSDN that the function FormatMessage can return a error message but i have no idea how to use it.I run on the only account on my machine (administrator) , and probably permissions are the cause because i see no other way. Can you explain how do i check that pls :D?thanks, Makaan   ;Quote:Original post by MakaanThanks for the replies;The functions RegCreateKeyEx returns number 5 and the key is absolutely new;i found on MSDN that the function FormatMessage can return a error message but i have no idea how to use it.I run on the only account on my machine (administrator) , and probably permissions are the cause because i see no other way. Can you explain how do i check that pls :D?thanks, MakaanFrom ym code:std::string FormatWindowsError(int nError){char* szMsgBuffer;FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,NULL, nError, 0, (LPSTR)&szMsgBuffer, 0, NULL);std::string strRet(szMsgBuffer);LocalFree(szMsgBuffer);return strRet;}Error code 5 is "Access Denied". So yes, permissions problem. You need Administrator privileges to write to HKLM.EDIT: Oh, you are Administrator... What OS are you using?   ;  tnxi have windows XP professional 32bitthanks, Makaan   ;Quote:and the key is absolutely newAre you absolutely sure that the KEY (HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run) is new? I'm sure that your VALUE (Dummy Name) is new though.I can't recall ever to stumble across a computer that doesn't have a Run key by default.