Question

I am writing an application in c++ that will be executed on Windows Vista. I want to add a registry entery to start my app along with windows, but I got an error: permission denied. How do I bypass that. Here is my code:

    void Persist::RunOnWindowsBoot()
{
     HKEY hKey;
     char ExeDir[MAX_PATH] = "E:\\Projects\\Coro\\Coro.exe"; 
     RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_QUERY_VALUE | KEY_SET_VALUE, &hKey);

     if(RegQueryValueEx(hKey, TEXT("System"), NULL, NULL, NULL, NULL) == ERROR_FILE_NOT_FOUND)
     {
              RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
              RegSetValueEx(hKey, "System", 0, REG_SZ, (const unsigned char*)ExeDir, MAX_PATH);
              RegCloseKey(hKey);
     }
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top