PDA

View Full Version : [C++] Creare una chiave di registro


Gotchabest
08-12-2011, 15:59
Vorrei scrivere un programmino per inserire una chiave di registro nel mio sistema in C++. Trovando questo (http://stackoverflow.com/questions/508614/create-a-new-windows-registry-key-using-c) su internet compila ma qualcosa di questo pezzo di codice fa sì che non mi funziona: precisamente mi da "Error creating key."

Chi mi può aiutare?

HKEY hKey;
LPCTSTR sk = TEXT("SOFTWARE\\Windows\\CurrentVersion\\Run\\PROVA");

LONG openRes = RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
sk,
0,
NULL,
REG_OPTION_BACKUP_RESTORE,
KEY_ALL_ACCESS,
NULL,
&hKey,
NULL);

if (openRes==ERROR_SUCCESS) {
printf("Success creating key.");
} else {
printf("Error creating key.");
}

Gotchabest
08-12-2011, 16:37
Potete anche chiudere, ho risolto con:

system("reg add HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /V NOMEAPPLICAZIONE /T REG_SZ /F /D PERCORSO");


Esempio:

system("reg add HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run /V UnaProva /T REG_SZ /F /D F:\\prova\\prova1.exe");

WarDuck
08-12-2011, 16:59
Se usi reg tantovale usare un file batch (.cmd), anziché usare C++ ;).