Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: Pablo Videla en 21 Noviembre 2009, 19:22 pm



Título: Problema al agregar al registro[Solucionado]
Publicado por: Pablo Videla en 21 Noviembre 2009, 19:22 pm
Código
  1.                System.Diagnostics.Process.Start("reg add \"HKLM/Software/Microsoft/Windows/CurrentVersion/Run\" /v \"giga2\" /d "+""+ Application.ExecutablePath.ToLower() +"");

me sale "Error... el sistema no puede hallar el archivo especificado, mi idea es que agregue al registro y se inicie automaticamente, que tengo de mal ahi?, gracias de antemano

SOLUCION:

Código
  1. static private bool ponerEnInicio(string nombreClave, string nombreApp)
  2.        {
  3.            // Resgistrará en Inicio del registro la aplicación indicada
  4.            // Devuelve True si todo fue bien, False en caso contrario
  5.            //
  6.            // Guardar la clave en el registro
  7.            // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
  8.            try
  9.            {
  10.                RegistryKey runK = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
  11.                // añadirlo al registro
  12.                // Si el path contiene espacios se debería incluir entre comillas dobles
  13.                if (nombreApp.StartsWith("\"") == false && nombreApp.IndexOf(" ") > -1)
  14.                {
  15.                    nombreApp = "\"" + nombreApp + "\"";
  16.                }
  17.                runK.SetValue(nombreClave, nombreApp);
  18.                return true;
  19.            }
  20.            catch (Exception ex)
  21.            {
  22.                Console.WriteLine("ERROR al guardar en el registro.{0}Seguramente no tienes privilegios suficientes.{0}{1}{0}---xxx---{2}", '\n', ex.Message, ex.StackTrace);
  23.                return false;
  24.            }
  25.        }  


Título: Re: Problema al agregar al registro
Publicado por: raul338 en 21 Noviembre 2009, 20:04 pm
Código
  1.                System.Diagnostics.Process.Start("reg add \"HKLM/Software/Microsoft/Windows/CurrentVersion/Run\" /v \"giga2\" /d "+""+ Application.ExecutablePath.ToLower() +"");

me sale "Error... el sistema no puede hallar el archivo especificado, mi idea es que agregue al registro y se inicie automaticamente, que tengo de mal ahi?, gracias de antemano

Creo que faltan un par de \"

y ademas, esa no es la forma de agregar registro desde programacion. Fijate este pequeño tutorial

http://www.elguille.info/net/dotnet/registroWindowsInicio.htm



Título: Re: Problema al agregar al registro
Publicado por: seba123neo en 21 Noviembre 2009, 20:06 pm
Process.Start es ejecutar, para agregar al registro usa la clase Registry...


Título: Re: Problema al agregar al registro
Publicado por: Pablo Videla en 21 Noviembre 2009, 20:25 pm
Ok, leere , gracias  ;D, les mantendre informado


Título: Re: Problema al agregar al registro [Solucionado]
Publicado por: Pablo Videla en 22 Noviembre 2009, 01:21 am
Excelente, lo acabo de probar y me funciono a la perfeccion, muchas gracias a todos. ;D