Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-12-2013
andres_89 andres_89 is offline
Miembro
 
Registrado: dic 2013
Posts: 46
Poder: 0
andres_89 Va por buen camino
Error! Crear valor en el registro

Hola a todos,

estoy tratando de crear una clave en el registro de windows, pero me lanza un error al momento de crearla, agrego que la compilación fue sin error, estuve viendo otros hilos abiertos en la página y logro solucionarme una parte pero lo principal no puedo, a ver si me dan una manito, les dejo los códigos que están en mi problema:

Primeramente empezare con "Leer un valor de una clave":

con este código puedo leer sin problemas:
Código:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TRegistry *Registry = new TRegistry(KEY_ALL_ACCESS);
    Registry->RootKey = HKEY_CURRENT_USER;

    // Poner true si queremos que cree la clave si ésta no existe
    if(Registry->KeyExists("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
    {
       Registry->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",false);
       ShowMessage(Registry->ReadString("miprograma"));
       Registry->CloseKey();
    }
 }
Pero cuando quiero leer "HKEY_LOCAL_MACHINE", no me muestra nada, pero se compila bien, a pesar que lo ejecute como administrador y tambien existe la clave, el código es este (solo modifique "HKEY_CURRENT_USER" por "HKEY_LOCAL_MACHINE"):

Código:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    TRegistry *Registry = new TRegistry(KEY_ALL_ACCESS);
    Registry->RootKey = HKEY_LOCAL_MACHINE;

    if(Registry->KeyExists("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
    {
       Registry->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",false);
       ShowMessage(Registry->ReadString("miprograma"));
       Registry->CloseKey();
    }

}
buscando por el foro pude encontrar solución, para leer "HKEY_LOCAL_MACHINE", agregando unas lineas y cambiando otra, el código es este:

Código:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// esta linea hace que me muestre la clave, diferenciando mi SO actual (WIndows 7 64 bits)
std::auto_ptr<TRegistry> rRegistro(new TRegistry(KEY_READ | KEY_WOW64_64KEY));

rRegistro->RootKey = HKEY_LOCAL_MACHINE;
    if(rRegistro->KeyExists("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
    {
       rRegistro->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",false);
       ShowMessage(rRegistro->ReadString("miprograma"));
       rRegistro->CloseKey();
    }

}
mas detallado con las librerias necesarias esta acá:

clubdelphi.com/foros/showpost.php?p=468929&postcount=9


amolde el código para crear llaves, pero aún asi no puedo crearlas en "HKEY_LOCAL_MACHINE", solo puedo en "HKEY_CURRENT_USER", este es el código:

Código:
    std::auto_ptr<TRegistry> Registry(new TRegistry(KEY_READ | KEY_WOW64_64KEY));
    
    Registry->RootKey = HKEY_LOCAL_MACHINE;

    if(Registry->KeyExists("Software\\Microsoft\\Windows\\CurrentVersion\\Run"))
    {
       Registry->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",false);
       Registry->WriteString("miprograma2","C:\\Video tutoriales\\registro\\pregistro.exe");
       Registry->CloseKey();
    }

    ShowMessage("Listo");
ahora mi pregunta es, si ya puedo leer claves desde "HKEY_LOCAL_MACHINE" agregando esas librerias que faltaban, porque no puedo crearlas?; pero puedo crear claves normalmente siempre en cuando este en "HKEY_CURRENT_USER", quedo atento a sus comentarios.

Saludos.
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
REG_DWORD leer y escribir un valor en el registro madmai Lazarus, FreePascal, Kylix, etc. 1 01-02-2010 08:43:46
como obtener valor del ultimo registro. Gaim2205 Varios 4 10-09-2007 22:02:17
Maxima valor de un nuevo registro Arturo_ Tablas planas 8 23-07-2007 22:14:32
Registro con valor BINARIO !!! Ledian_Fdez Varios 1 07-06-2007 00:25:58
Error: El valor EOF o BOF es True o el actuañ registro de eliminó lavtaro Conexión con bases de datos 2 30-06-2003 11:39:44


La franja horaria es GMT +2. Ahora son las 19:38:05.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi