Oppure

Loading
08/11/07 18:36
Beowulf
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??
#include <windows.h>
using namespace std;
int main() {

char buffer[60];
unsigned long size = sizeof(buffer);
strcpy(buffer,"This Value was written to the registry");
HKEY software;
HKEY mykey;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",&software);
RegCreateKey(software,"provachiave",&mykey);
RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\mioprog.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
}
aaa
08/11/07 18:42
WARRIOR
#include <windows.h> 
using namespace std; 
int main() { 

char buffer[60]; 
unsigned long size = sizeof(buffer); 
strcpy(buffer,"This Value was written to the registry"); 
HKEY software; 
HKEY mykey; 
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",&software); 
RegCreateKey(software,"provachiave",&mykey); 
RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\mioprog.exe",NULL,REG_SZ,(LPBYTE)buffer,size); 
RegCloseKey(mykey); 
RegCloseKey(software); 
}


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:
aaa
08/11/07 18:49
Beowulf
ok, grazie mille oltre che per l'aiuto per la rapidità con cui mi hai risposto :k:
adesso provo
aaa
08/11/07 19:21
Beowulf
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++
aaa
08/11/07 20:19
WARRIOR
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:
aaa
08/11/07 21:16
Beowulf
non ho modificato niente...ecco il source che ho compilato:
#include <iostream>
#include <windows.h>
using namespace std;

int main() {

char buffer[60];
unsigned long size = sizeof(buffer);
strcpy(buffer,"This Value was written to the registry");
HKEY software;
HKEY mykey;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",&software);
RegCreateKey(software,"provachiave",&mykey);
RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\firewall.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
} 

infatti non capisco..dipenderà da dev-c++??
aaa
08/11/07 21:18
Beowulf
non ho modificato niente...ecco il source che ho compilato:
#include <iostream>
#include <windows.h>
using namespace std;

int main() {

char buffer[60];
unsigned long size = sizeof(buffer);
strcpy(buffer,"This Value was written to the registry");
HKEY software;
HKEY mykey;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",&software);
RegCreateKey(software,"provachiave",&mykey);
RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\firewall.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
} 

infatti non capisco..dipenderà da dev-c++??
aaa
09/11/07 17:43
WARRIOR
Postato originariamente da Beowulf:

non ho modificato niente...ecco il source che ho compilato:
#include <iostream>
#include <windows.h>
using namespace std;

int main() {

char buffer[60];
unsigned long size = sizeof(buffer);
strcpy(buffer,"This Value was written to the registry");
HKEY software;
HKEY mykey;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",&software);
RegCreateKey(software,"provachiave",&mykey);
RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\firewall.exe",NULL,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
} 

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


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

#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;

int main() {

char buffer[60];
unsigned long size = sizeof(buffer);
strcpy(buffer,"This Value was written to the registry");
HKEY software;
HKEY mykey;
RegCreateKey(HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Run",&software);
RegCreateKey(software,"provachiave",&mykey);
RegSetValueEx(mykey,"C:\Documents and Settings\lory\Desktop\@Lory@win\programmi in c++\firewall.exe",0,REG_SZ,(LPBYTE)buffer,size);
RegCloseKey(mykey);
RegCloseKey(software);
} 


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