Hola, estoy intentando crear un registro en c++ con APIs para que cuando reinicie el pc ejecute un programa. De momento lo estoy intentando con este codigo pero algo falla y no se que puede ser. Un saludo.
#include <windows.h>
int main()
{
LPSTR lpSubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hkResult = 0;
RegOpenKeyEx(HKEY_CURRENT_USER, lpSubKey, 0, KEY_WRITE, &hkResult);
{
HKEY hKey = 0;
LPSTR lpValueName = "ejemplo";
LPSTR lpData = "C:\\ejemplo.exe";
RegSetValueEx(hKey, lpValueName, 0, REG_SZ, (LPBYTE)lpData, lstrlen(lpData));
RegCloseKey(hKey);
}
}
Consulta la MSDN y veras el error facilmente
RegSetValueEx (http://msdn.microsoft.com/en-us/library/ms724923%28VS.85%29.aspx)
CitarhKey [in]
A handle to an open registry key. The key must have been opened with the KEY_SET_VALUE access right. For more information, see Registry Key Security and Access Rights. (http://msdn.microsoft.com/en-us/library/ms724878%28v=VS.85%29.aspx)
Te estas equivocando en el parámetro que le pasas a RegSetValueEx, debería ser "hkResult".
Saludos
Lo del parámetro es culpa mía, le pasé el ejemplo y, me descuidé en este parámetro, perdona por el error tonto :(
Saludos :P