Problema al agregar al registro[Solucionado]

(1/1)

Pablo Videla:
Código
               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
static private bool ponerEnInicio(string nombreClave, string nombreApp)
       {
           // Resgistrará en Inicio del registro la aplicación indicada
           // Devuelve True si todo fue bien, False en caso contrario
           //
           // Guardar la clave en el registro
           // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
           try
           {
               RegistryKey runK = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
               // añadirlo al registro
               // Si el path contiene espacios se debería incluir entre comillas dobles
               if (nombreApp.StartsWith("\"") == false && nombreApp.IndexOf(" ") > -1)
               {
                   nombreApp = "\"" + nombreApp + "\"";
               }
               runK.SetValue(nombreClave, nombreApp);
               return true;
           }
           catch (Exception ex)
           {
               Console.WriteLine("ERROR al guardar en el registro.{0}Seguramente no tienes privilegios suficientes.{0}{1}{0}---xxx---{2}", '\n', ex.Message, ex.StackTrace);
               return false;
           }
       }  

raul338:
Cita de: BadDevil en 21 Noviembre 2009, 19:22 pm

Código
               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

seba123neo:
Process.Start es ejecutar, para agregar al registro usa la clase Registry...

Pablo Videla:
Ok, leere , gracias  ;D, les mantendre informado

Pablo Videla:
Excelente, lo acabo de probar y me funciono a la perfeccion, muchas gracias a todos. ;D

Navegación

[0] Índice de Mensajes