• Lunes 8 de Julio de 2024, 03:27

Autor Tema:  Agregar Aplicacion Al Inicio (msconfig)  (Leído 1513 veces)

Nogard

  • Miembro activo
  • **
  • Mensajes: 27
    • Ver Perfil
Agregar Aplicacion Al Inicio (msconfig)
« en: Martes 18 de Enero de 2005, 23:09 »
0
Hola a todos.
Me gustaria saber si alguien puede darme alguna idea de como hacer que mi aplicacion se agregue automaticamente al inicio de  windows por medio de MSCONFIG.

He hecho algunas pruebas con la manipulacion de APIS pero no he tenido exito, de verdad agradeceria cualquier idea o sugerencia que me pueda ayudar.

Gracias de antemano.  B)

Brroz

  • Miembro de PLATA
  • *****
  • Mensajes: 1058
    • Ver Perfil
Re: Agregar Aplicacion Al Inicio (msconfig)
« Respuesta #1 en: Miércoles 19 de Enero de 2005, 14:52 »
0
Hola Nogard.

Con w9x (y supongo que con nt y xp lo mismo, pero no lo he probado) puedes agregar el correspondiente valor en una de estas claves del registro:

Para ejecutar siempre al inicio:
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

Para ejecutar una sola vez en el siguiente inicio:
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce

Para ejecutar como un servicio:
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices

Para ejecutar como servicio una sola vez:
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce

Para agregar el correspondiente valor puedes usar algo así:

Código: Text
  1.  
  2. Option Explicit
  3.  
  4. Private Const HKEY_LOCAL_MACHINE = &H80000002
  5.  
  6. Private Const ERROR_SUCCESS = 0&
  7.  
  8. Private Const KEY_QUERY_VALUE = &H1
  9. Private Const KEY_SET_VALUE = &H2
  10. Private Const KEY_CREATE_SUB_KEY = &H4
  11. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
  12. Private Const KEY_NOTIFY = &H10
  13. Private Const KEY_CREATE_LINK = &H20
  14. Private Const SYNCHRONIZE = &H100000
  15. Private Const STANDARD_RIGHTS_ALL = &H1F0000
  16. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE))
  17.  
  18. Private Type SECURITY_ATTRIBUTES
  19.     nLength As Long
  20.     lpSecurityDescriptor As Long
  21.     bInheritHandle As Long
  22. End Type
  23.  
  24. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
  25.  
  26. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  27.  
  28. Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
  29.  
  30. Public Function EjecutarAlInicio(Byval Descripcion as string, Byval CmdLine As string) As Boolean
  31.  
  32.     Dim lhKey1 As Long, lhKey2 As Long, lRc As Long
  33.  
  34.     lRc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software", 0&, KEY_QUERY_VALUE, lhKey1)
  35.     If lRc <> ERROR_SUCCESS Then Exit Function
  36.    
  37.     lRc = RegOpenKeyEx(lhKey1, "Microsoft", 0&, KEY_QUERY_VALUE, lhKey2)
  38.     RegCloseKey lhKey1
  39.     If lRc <> ERROR_SUCCESS Then Exit function
  40.    
  41.     lRc = RegOpenKeyEx(lhKey2, "Windows", 0&, KEY_QUERY_VALUE, lhKey1)
  42.     RegCloseKey lhKey2
  43.     If lRc <> ERROR_SUCCESS Then Exit function
  44.    
  45.     lRc = RegOpenKeyEx(lhKey1, "CurrentVersion", 0&, KEY_QUERY_VALUE, lhKey2)
  46.     RegCloseKey lhKey1
  47.     If lRc <> ERROR_SUCCESS Then Exit Function
  48.    
  49.     lRc = RegOpenKeyEx(lhKey2, "Run", 0&, KEY_ALL_ACCESS, lhKey1)
  50.     RegCloseKey lhKey2
  51.     If lRc <> ERROR_SUCCESS Then Exit Function
  52.  
  53.     CmdLine = CmdLine & Chr(0)
  54.     lRc = RegSetValueEx(lhKey1, Descripcion, 0&, 1&, ByVal CmdLine, Len(CmdLine))
  55.     EjecutarAlInicio = (lRc = ERROR_SUCCESS)
  56.    
  57. End Sub
  58.  
  59.  

Espero que sirva.

Abur.