Visual Basic - como hacer que un programa se abra solo

Life is soft - evento anual de software empresarial
 
Vista:

como hacer que un programa se abra solo

Publicado por istari (1 intervención) el 11/09/2004 04:49:20
Hola. Necesito alguien que me pueda ayudar. quisiera saber como puedo hacer para que cuando se habra un programa hecho en vb6 por primera vez, se habra cada vez que inicie windows. Necesito saberlo para un proyecto.

Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:como hacer que un programa se abra solo

Publicado por Ruri (583 intervenciones) el 11/09/2004 15:58:27
istari:
Debe colocarse en el registro de arraque. Para ello necesitás un módulo del Api. Hace poco le envié el siguiente módulo a otra persona de este foro. Yo lo probé muchas veces y funciona bien:
######################################################
Option Explicit
DefLng A-Z

Public Const HKEY_CURRENT_USER As Long = &H80000001
Public Const HKEY_LOCAL_MACHINE As Long = &H80000002

Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes As Long, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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, ByVal lpData As String, ByVal cbData As Long) As Long

Private Const REG_SZ = 1
Private Const REG_OPTION_NON_VOLATILE = 0

Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_LINK = &H20
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const SYNCHRONIZE = &H100000

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))
Private Const ERROR_SUCCESS = 0&

Public Function ColocarProgramaEnElRun(ByVal NombrePrograma As String, ByVal RutaPrograma As String) As Boolean
Dim hdlHandle As Long, lngCreada As Long, strBuffer As String, lngBuffer As Long, Clave As String, hKey As Long
Clave = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
hKey = HKEY_CURRENT_USER '(Usuario corriente) HKEY_LOCAL_MACHINE (Todos los usuarios, la máquina)
strBuffer = RutaPrograma & vbNullChar
lngBuffer = Len(RutaPrograma) + 1
If RegCreateKeyEx(hKey, Clave, 0, vbNullString, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, hdlHandle, lngCreada) <> ERROR_SUCCESS Then GoTo NoReg
If RegSetValueEx(hdlHandle, NombrePrograma, 0, REG_SZ, strBuffer, lngBuffer) <> ERROR_SUCCESS Then GoTo NoReg
RegCloseKey hdlHandle
ColocarProgramaEnElRun = True
Exit Function
NoReg:
RegCloseKey hdlHandle
ColocarProgramaEnElRun = False
End Function
#######################################################
Utilizarlo no es difícil, es necesario pasarle dos parámetros, la ruta del ejecutable que vas a colocar en el run y un identificador (en el run pueden haber muchos programas). Por ejemplo:

'Arranca el emule y lo identifica como "Mulita"
ColocarProgramaEnElRun "C:\Archivos de programa\emule\emule.exe", "Mulita"

Sirve con cualquier programa, sin importar en que este hecho.

Saludos Ruri
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:como hacer que un programa se abra solo

Publicado por Dante (72 intervenciones) el 12/09/2004 15:12:42
Creo que lo único que tienes que hacer es colocarlo en el menú de inicio y automáticamente arrancará cuando arranque la PC.
El método depende del sistema operativo. Generalmente sólo hay que arrastrar el icono y se crea un acceso directo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar