Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - chiavi di registro
Forum - C/C++ - chiavi di registro

Avatar
Beowulf (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/11/2007

Segnala al moderatore
Postato alle 19:36
Giovedì, 08/11/2007
salve a tutti, oggi ho provato a creare una chiave di registro in c++
però il codice che ho trovato e modificato non funziona...
ve lo posto, potete aiutarmi??
Codice sorgente - presumibilmente C++

  1. #include <windows.h>
  2. using namespace std;
  3. int main() {
  4.  
  5. char buffer[60];
  6. unsigned long size = sizeof(buffer);
  7. strcpy(buffer,"This Value was written to the registry");
  8. HKEY software;
  9. HKEY mykey;
  10. RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&software);
  11. RegCreateKey(software,"provachiave",&mykey);
  12. RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\mioprog.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
  13. RegCloseKey(mykey);
  14. RegCloseKey(software);
  15. }


PM Quote
Avatar
WARRIOR (Ex-Member)
Guru


Messaggi: 627
Iscritto: 30/03/2007

Segnala al moderatore
Postato alle 19:42
Giovedì, 08/11/2007
Codice sorgente - presumibilmente C++

  1. #include <windows.h>
  2. using namespace std;
  3. int main() {
  4.  
  5. char buffer[60];
  6. unsigned long size = sizeof(buffer);
  7. strcpy(buffer,"This Value was written to the registry");
  8. HKEY software;
  9. HKEY mykey;
  10. RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&software);
  11. RegCreateKey(software,"provachiave",&mykey);
  12. RegSetValueEx(mykey,"C:\\Documents and Settings\\lory\\Desktop\\@Lory@win\\programmi in c++\\mioprog.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
  13. RegCloseKey(mykey);
  14. RegCloseKey(software);
  15. }



Non ti funzionava perchè dovevi mettere il doppio carattere di backslash nel percorso, altrimenti prende le lettere che lo seguono come caratteri escape. ;)
Ho provato il codice, a me funziona.

:k:

PM Quote
Avatar
Beowulf (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/11/2007

Segnala al moderatore
Postato alle 19:49
Giovedì, 08/11/2007
ok, grazie mille oltre che per l'aiuto per la rapidità con cui mi hai risposto :k:
adesso provo

PM Quote
Avatar
Beowulf (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/11/2007

Segnala al moderatore
Postato alle 20:21
Giovedì, 08/11/2007
ho provato come hai detto te..il compilatore mi da questo errore:
18 C:\Documents and Settings\lory\Desktop\registry.cpp [Warning] passing NULL used for non-pointer converting 3 of `LONG RegSetValueExA(HKEY__*, const CHAR*, DWORD, DWORD, const BYTE*, DWORD)'

uso dev-c++

PM Quote
Avatar
WARRIOR (Ex-Member)
Guru


Messaggi: 627
Iscritto: 30/03/2007

Segnala al moderatore
Postato alle 21:19
Giovedì, 08/11/2007
Dà l'errore sulla funzione RegSetValueExA....ma non è inserita nel programma... :-|
Per caso hai sostituito la funzione RegSetValueEx?....A me la chiave viene aggiunta regolarmente. :k:

PM Quote
Avatar
Beowulf (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/11/2007

Segnala al moderatore
Postato alle 22:16
Giovedì, 08/11/2007
non ho modificato niente...ecco il source che ho compilato:
Codice sorgente - presumibilmente C++

  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char buffer[60];
  8. unsigned long size = sizeof(buffer);
  9. strcpy(buffer,"This Value was written to the registry");
  10. HKEY software;
  11. HKEY mykey;
  12. RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&software);
  13. RegCreateKey(software,"provachiave",&mykey);
  14. RegSetValueEx(mykey,"C:\\Documents and Settings\\lory\\Desktop\\@Lory@win\\programmi in c++\\firewall.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
  15. RegCloseKey(mykey);
  16. RegCloseKey(software);
  17. }


infatti non capisco..dipenderà da dev-c++??

PM Quote
Avatar
Beowulf (Normal User)
Newbie


Messaggi: 8
Iscritto: 08/11/2007

Segnala al moderatore
Postato alle 22:18
Giovedì, 08/11/2007
non ho modificato niente...ecco il source che ho compilato:
Codice sorgente - presumibilmente C++

  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char buffer[60];
  8. unsigned long size = sizeof(buffer);
  9. strcpy(buffer,"This Value was written to the registry");
  10. HKEY software;
  11. HKEY mykey;
  12. RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&software);
  13. RegCreateKey(software,"provachiave",&mykey);
  14. RegSetValueEx(mykey,"C:\\Documents and Settings\\lory\\Desktop\\@Lory@win\\programmi in c++\\firewall.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
  15. RegCloseKey(mykey);
  16. RegCloseKey(software);
  17. }


infatti non capisco..dipenderà da dev-c++??

PM Quote
Avatar
WARRIOR (Ex-Member)
Guru


Messaggi: 627
Iscritto: 30/03/2007

Segnala al moderatore
Postato alle 18:43
Venerdì, 09/11/2007
Testo quotato

Postato originariamente da Beowulf:

non ho modificato niente...ecco il source che ho compilato:
Codice sorgente - presumibilmente C++

  1. #include <iostream>
  2. #include <windows.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. char buffer[60];
  8. unsigned long size = sizeof(buffer);
  9. strcpy(buffer,"This Value was written to the registry");
  10. HKEY software;
  11. HKEY mykey;
  12. RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&software);
  13. RegCreateKey(software,"provachiave",&mykey);
  14. RegSetValueEx(mykey,"C:\\Documents and Settings\\lory\\Desktop\\@Lory@win\\programmi in c++\\firewall.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
  15. RegCloseKey(mykey);
  16. RegCloseKey(software);
  17. }


infatti non capisco..dipenderà da dev-c++??



Non penso, perchè uso anche io Dev-C++.

Codice sorgente - presumibilmente C++

  1. #include <iostream>
  2. #include <windows.h>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. char buffer[60];
  9. unsigned long size = sizeof(buffer);
  10. strcpy(buffer,"This Value was written to the registry");
  11. HKEY software;
  12. HKEY mykey;
  13. RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&software);
  14. RegCreateKey(software,"provachiave",&mykey);
  15. RegSetValueEx(mykey,"C:\\Documents and Settings\\lory\\Desktop\\@Lory@win\\programmi in c++\\firewall.exe",0,REG_SZ,(LPBYTE)buffer,size);
  16. RegCloseKey(mykey);
  17. RegCloseKey(software);
  18. }



Ho sostituito il NULL con uno zero, prova in questo modo.

PM Quote