Ahoj, potřeboval bych pomoct se zápisem do registru, konkrétně do :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Prosím o podrobnější návod.
Díky
Fórum › C / C++
Zápis do registru

ok, muzes dat
HKEY h1;char *jm="file.exe";
RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&h1);
nebo
RegCreateKey(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",&h1);
v h1 je handle otevreneho klice pak konkretni polozku zapises:
RegSetValueEx(h1,"1",0,REG_SZ,(const unsigned char*)jm,strlen(jm));
pribyde polozka 1 s obsahem retezce file.exe
na vyber (krom REG_SZ) je:
REG_BINARY Binary data in any form.
REG_DWORD A 32-bit number.
REG_DWORD_LITTLE_ENDIAN A 32-bit number in little-endian format (same as REG_DWORD). In little-endian format, the most significant byte of a word is the high-order word. This is the most common format for computers running Windows NT and Windows 95.
REG_DWORD_BIG_ENDIAN A 32-bit number in big-endian format. In big-endian format, the most significant byte of a word is the low-order word.
REG_EXPAND_SZ A null-terminated string that contains unexpanded references to environment variables (for example, "%PATH%"). It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.
REG_LINK A Unicode symbolic link.
REG_MULTI_SZ An array of null-terminated strings, terminated by two null characters.
REG_NONE No defined value type.
REG_RESOURCE_LIST A device-driver resource list.
REG_SZ A null-terminated string. It will be a Unicode or ANSI string depending on whether you use the Unicode or ANSI functions.
Takže tohle je zdroják?
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
HKEY h1;
char *jm = "C:\\file.exe";
RegOpenKey(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",&h1);
RegSetValueEx(h1,"1",0,REG_SZ,(const unsigned char*)jm,strlen(jm));
}
Nějak mi nefunguje, úspěšně se builne ale do registrů se nic "nezapíše".
Můžeš mi napsat celý zdrojový kód který zapíše soubor file.exe (uložený v C:\ ) do
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
JJinak mám windows 7 64bit
hele asi po 40 sekundach jsem si opravil a editnul nahore ty lomitka, MUSI BYT PO 2!! ty si asi stihl moji prvni verzi :D
Už jsem to vyřešil. NEvím proč ale nejde mi zapsat do
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
tak jsem to zkusil do
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
a funguje to díky!
tak pri malejch pravech se to od Visty zapisuje tam, mozna by ti pomohlo i volani RegCreateKeyEx() s KEY_ALL_ACCESS.
Hele, ještě bych potřeboval toto:
HKEY h1;
char *jm = "%HOMEDRIVE%\\file.exe"; // %homedrive% zde nefunguje, nevím proč
RegOpenKey(HKEY_CURRENT_USER,"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",&h1);
RegSetValueEx(h1,"1",0,REG_SZ,(const unsigned char*)jm,strlen(jm));
%homedrive% mi nefunguje. Zapiše do registru ale po spuštění se nic nespustí ? Co s tím?
to je ovsem "dokonaly" popis problemu.... v registru je co? C:\file.exe ? A chces aby se spustilo moje file.exe ktere ti tam na disku C shodou nahod existuje?
A tady http://msdn.microsoft.com/en-us/library/ms724871(v=VS.85).aspx ses díval?
V tom odkazu, co ti dal zdenda ... funkce typu RegDelete... http://msdn.microsoft.com/en-us/library/ms724875(v=VS.85).aspx případně můžeš vyzkoušet shell funkce jako třeba SHDeleteKey http://msdn.microsoft.com/en-us/library/bb773486(v=VS.85).aspx.

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Zapis do registru v c — založil Anonymní uživatel
Zápis do registru — založil Kenvelo
Zápis binární hodnoty do registru — založil MaxDevaine
Přístup k registru pomocí dat v registru — založil yaqwsx
Edit Registru — založil Odin
Moderátoři diskuze