Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Eliminar registro de Windows (https://www.clubdelphi.com/foros/showthread.php?t=9039)

verm83 11-04-2004 19:40:36

Eliminar registro de Windows
 
Hola de nuevo.
Me interesaría borrar un registro de Windows, dentro de HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\, para que cierta aplicación arranque o no junto con Windows. Para ello he usado la siguiente función:

Código:

procedure TvPrograma.abrirEnInicio(iOpcion:integer);
var
    Registro:TRegistry;
begin
    // Crea una clave en el registro
    Registro:=TRegistry.create;
    Registro.RootKey:=HKEY_LOCAL_MACHINE;
    // Según iOpcion, borramos o añadimos la clave
    case iOPcion of
        0: if Registro.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run\',FALSE) then
              Registro.WriteString('MiPrograma','');
        1: if Registro.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',FALSE) then
              Registro.WriteString('MiPrograma',ExtractFilePath(ExpandFileName(ParamStr(0)))+'MiPrograma.exe');
    end;
    Registro.Destroy;
end;

Como se ve, cuando me interesa eliminarla (pasándole 0 a la función), lo que realmente hace es establecer la ruta a una cadena vacía. Esto es así porque DeleteKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run\MiPrograma') no me funcionó. ¿Alguien sabe por qué? ¿Cómo podría hacerlo? No me convence establecer la ruta a una cadena vacía.

Gracias anticipadas.

verm83 11-04-2004 22:27:39

Me acabo de responder yo sólo :D
En vez de DeleteKey(), pues abres la ruta del registro con OpenKey(), y luego borras el valor que deseas, indicando su nombre, usando DeleteValue(), quedando así el código:


Código:

    case iOPcion of
        0: if Registro.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run\',FALSE) then
              Registro.DeleteValue('MiPrograma');
        1: if Registro.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',FALSE) then
              Registro.WriteString('MiPrograma',ExtractFilePath(ExpandFileName(ParamStr(0)))+'MiPrograma.exe');
    end;

Espero que a alguien le sirva de ayuda ;)


La franja horaria es GMT +2. Ahora son las 21:00:20.

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