2010-07-14 11 views

Respuesta

8

se puede ejecutar cada vez que las ventanas comienzan utilizando sólo 2 líneas de código de abajo

RegistryKey Key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);      
    Key.SetValue("AppName", System.Reflection.Assembly.GetEntryAssembly().Location); 

Si usted realmente necesita para crear un acceso directo de inicio, aquí está el código

private void CreateShortcutInStartUP() 
     { 
      try 
      { 
       Assembly code = Assembly.GetExecutingAssembly(); 
       String company = Application.CompanyName; 
       String ApplicationName = Application.ProductName; 

       if(company != "" && ApplicationName != "") 
       { 
        String DesktopPath= Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + ApplicationName + @".appref-ms"; 
        String ShortcutName= Environment.GetFolderPath(Environment.SpecialFolder.Programs) + @"\" + company + @"\" + ApplicationName + @".appref-ms"; 
        if (System.IO.File.Exists(ShortcutName)) 
         System.IO.File.Copy(ShortcutName, DesktopPath, true); 

       } 
      } 
      catch(Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     } 

Actualmente estoy usando el código anterior para que pueda simplemente copiar pegar. Asegúrese de tener el nombre de la empresa de configuración.

+0

usando System.Reflection; – Eric

Cuestiones relacionadas