Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ writing to registry doesn't work in my code?
    text
    copied!<p>My friend and I have written this code to modify the registry, but when we run it it doesn't seem to write the values to the registry but only check if they are set up correctly. If they where set correctly before the program doesn't give any pop ups. But if the registry keys are not matching then the program is supposed to write the correct registry values, but it doesn't right now and we have no clue why its not working...</p> <p>here is the full code:</p> <pre><code>if (version.dwMajorVersion &gt;= 6) { HKEY ErrMode; LONG res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Control\\Windows", 0, KEY_READ | KEY_WRITE, &amp;ErrMode); if (res == ERROR_SUCCESS) { DWORD ErrorMode; DWORD DRlen = sizeof(DWORD); DWORD SUlen = sizeof(DWORD); if (RegQueryValueEx(ErrMode, "ErrorMode", 0, NULL, (LPBYTE)&amp;ErrorMode, &amp;DRlen) == ERROR_SUCCESS) { if (ErrorMode != 2) // any of errormode is non-2 { if (MessageBox(NULL, "Windows Error Reporting is still turned on.\r\nThis program may not work correctly with reporting turned on. Shall I disable it?\r\nNote:The readme explains how you can disable and enable Error Reporting under Windows)","Windows Error Reporting:", MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL) == IDYES) { ErrorMode = 2; // change local DRlen = sizeof(DWORD); SUlen = sizeof(DWORD); if (RegSetValueEx(ErrMode,"ErrorMode",2, REG_DWORD, (LPBYTE)&amp;ErrorMode, DRlen) != ERROR_SUCCESS) { char* buff = new char[1024]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,res,0,buff,1024,0); MessageBox(NULL, buff,"Error...", MB_OK | MB_ICONEXCLAMATION); delete[] buff; ok = false; } } else ok = false; } } if (RegCloseKey(ErrMode) != ERROR_SUCCESS) MessageBox(NULL, "Could not close Registry Key handle.","Error...",MB_OK | MB_ICONEXCLAMATION); } else { char* buff = new char[1024]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,res,0,buff,1024,0); CString message; message.Format("Could not read from registry. Make sure you have either turned off error reporting\r\nor that you run this program from a privileged account.\r\nError: %s",buff); MessageBox(NULL, message.GetBuffer(),"Error...",MB_OK | MB_ICONEXCLAMATION); delete[] buff; ok = false; } HKEY DontSUI; res = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\Windows Error Reporting", 0, KEY_READ | KEY_WRITE, &amp;DontSUI); if (res == ERROR_SUCCESS) { DWORD DontShowUI; DWORD DRlen = sizeof(DWORD); DWORD SUlen = sizeof(DWORD); if (RegQueryValueEx(DontSUI, "DontShowUI", 0, NULL, (LPBYTE)&amp;DontShowUI, &amp;DRlen) == ERROR_SUCCESS) { if (DontShowUI != 1) // any of DontShowUI is non 1 { if (MessageBox(NULL, "Windows Error Reporting is still turned on.\r\nThis program may not work correctly with reporting turned on. Shall I disable it?\r\nNote:The readme explains how you can disable and enable Error Reporting under Windows)","Windows Error Reporting:", MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL) == IDYES) { DontShowUI = 1; // change local DRlen = sizeof(DWORD); SUlen = sizeof(DWORD); if (RegSetValueEx(DontSUI,"DontShowUI",1, REG_DWORD, (LPBYTE)&amp;DontShowUI, DRlen) != ERROR_SUCCESS) { char* buff = new char[1024]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,res,0,buff,1024,0); MessageBox(NULL, buff,"Error...", MB_OK | MB_ICONEXCLAMATION); delete[] buff; ok = false; } } else ok = false; } } if (RegCloseKey(DontSUI) != ERROR_SUCCESS) MessageBox(NULL, "Could not close Registry Key handle.","Error...",MB_OK | MB_ICONEXCLAMATION); } else { char* buff = new char[1024]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,res,0,buff,1024,0); CString message; message.Format("Could not read from registry. Make sure you have either turned off error reporting\r\nor that you run this program from a privileged account.\r\nError: %s",buff); MessageBox(NULL, message.GetBuffer(),"Error...",MB_OK | MB_ICONEXCLAMATION); delete[] buff; ok = false; } if (!ok) { MessageBox(NULL,"Windows Error Reporting may still be active.\r\nThis program may not function correctly.","Warning",MB_ICONWARNING |MB_OK); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload