Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Psyke1 en 4 Diciembre 2012, 10:25 am



Título: No consigo que mi app se ejecute al inicio
Publicado por: Psyke1 en 4 Diciembre 2012, 10:25 am
Tengo Windows 7.

Copio mi exe en la carpeta de inicio, reinicio, pero no se ejecuta.
También he probado a añadir una clave en el registro y nada...
Puede ser porque mi exe requiere permisos de administrador pues si creo un programa que tan sólo te muestre un MsgBox funciona con cualquiera de los métodos anteriores... :P

¿Alguna solución? ???

DoEvents! :P


Título: Re: No consigo que mi app se ejecute al inicio
Publicado por: raul338 en 4 Diciembre 2012, 15:07 pm
el agregado al registro o a la carpeta inicio, debes hacerlo cuando estes en modo administrador, una vez hecho eso ya no necesitas el permiso, y se ejecuta estando en modo.... "protegido"


Título: Re: No consigo que mi app se ejecute al inicio
Publicado por: Karcrack en 4 Diciembre 2012, 15:27 pm
HKCU + %APPDATA% no debería darte problemas :-\


Título: Re: No consigo que mi app se ejecute al inicio
Publicado por: yum-kax en 4 Diciembre 2012, 16:23 pm
Si quiere hacerlo mas silencioso podes usar el svrany y ejecutarlo como un servicio ;). No hace falta que el usuario se loggee, el programa ya va a haber iniciado.
sino fijate no estar errando de carpeta, me ha pasado que tenia una carpeta "inicio" pero en realidad la carpeta era "start up" y por eso no me funcionaba. Esas cosas raras que pasaron en vista y seven de "program files" y "archivos de programas"..

PD: fijate que a tu programa no lo este bloqueando el antivirus.
espero que te sirva.


Título: Re: No consigo que mi app se ejecute al inicio
Publicado por: Psyke1 en 4 Diciembre 2012, 18:16 pm
Mirad, hice unas pruebas con esta función:

Código
  1. Option Explicit
  2.  
  3. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  4. 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
  5. 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
  6.  
  7. Private Const HKEY_CURRENT_USER     As Long = &H80000001
  8. Private Const KEY_WRITE             As Long = &H20006
  9. Private Const REG_SZ                As Long = &H1
  10.  
  11. Public Function PutOnStartUp(ByVal sPath As String) As Boolean
  12. Dim hRegkey                         As Long
  13.  
  14.    If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, hRegkey) = 0 Then
  15.        sPath = sPath & vbNullChar
  16.        PutOnStartUp = RegSetValueEx(hRegkey, "My App", 0, REG_SZ, ByVal sPath, Len(sPath)) = 0
  17.        RegCloseKey hRegkey
  18.    End If
  19. End Function



PRUEBA UNO:

Código
  1. Private Sub Form_Load()
  2. Dim sPath      As String
  3.  
  4.    sPath = App.Path & "\" & App.EXEName & ".exe"
  5.  
  6.    If PutOnStartUp(sPath) Then
  7.        Me.BackColor = vbGreen
  8.    Else
  9.        Me.BackColor = vbRed
  10.    End If
  11.  
  12.    Me.AutoRedraw = True
  13.    Me.Print sPath
  14. End Sub

  • Compilo en el escritorio.
  • Lo ejecuto.
  • Reinicio y efectivamente, se ha ejecutado correctamente desde mi escritorio ;-)

(http://oi45.tinypic.com/34sle06.jpg)



PRUEBA DOS:

Código
  1. Private Sub Form_Load()
  2. Dim sPath      As String
  3. Dim sDest      As String
  4.  
  5.    sPath = App.Path & "\" & App.EXEName & ".exe"
  6.    sDest = Environ("tmp") & "\Test.exe"
  7.  
  8.    FileCopy sPath, sDest
  9.  
  10.    If PutOnStartUp(sDest) Then
  11.        Me.BackColor = vbGreen
  12.    Else
  13.        Me.BackColor = vbRed
  14.    End If
  15.  
  16.    Me.AutoRedraw = True
  17.    Me.Print sPath
  18. End Sub

  • Compilo en el escritorio.
  • Lo ejecuto.
  • Compruebo que se ha copiado en la carpeta temporal
  • Borro el del escritorio por si las moscas.
  • Reinicio y... ¡CRASH!

Citar
Error 70: Permiso denegado

¿Qué pasa aquí? :o

DoEvents! :P


Título: Re: No consigo que mi app se ejecute al inicio
Publicado por: Karcrack en 4 Diciembre 2012, 19:33 pm
¿Ese error no será porque se está reescribiendo a sí mismo? :rolleyes:

PD: Prueba con %APPDATA% :-*


Título: Re: No consigo que mi app se ejecute al inicio
Publicado por: Psyke1 en 4 Diciembre 2012, 20:43 pm
He cambiado lo que dices, ahora hago esto:
Código
  1. Option Explicit
  2.  
  3. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
  4. 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
  5. 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
  6.  
  7. Private Const HKEY_CURRENT_USER     As Long = &H80000001
  8. Private Const KEY_WRITE             As Long = &H20006
  9. Private Const REG_SZ                As Long = &H1
  10.  
  11. Public Function PutOnStartUp(ByVal sPath As String) As Boolean
  12. Dim hRegkey                         As Long
  13.  
  14.    If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, hRegkey) = 0 Then
  15.        sPath = sPath & vbNullChar
  16.        PutOnStartUp = RegSetValueEx(hRegkey, "Karcry", 0, REG_SZ, ByVal sPath, Len(sPath)) = 0
  17.        RegCloseKey hRegkey
  18.    End If
  19. End Function
  20.  
  21. Private Sub Form_Load()
  22. Dim sPath      As String
  23. Dim sDest      As String
  24.  
  25.    sPath = App.Path & "\" & App.EXEName & ".exe"
  26.    sDest = Environ("APPDATA") & "\Test.exe"
  27.  
  28.    FileCopy sPath, sDest
  29.  
  30.    If PutOnStartUp(sDest) Then
  31.        Me.BackColor = vbGreen
  32.    Else
  33.        Me.BackColor = vbRed
  34.    End If
  35.  
  36.    Me.AutoRedraw = True
  37.    Me.Print sPath
  38.    Me.Print sDest
  39. End Sub


    • Compilo.
    • Ejecuto desde el escritorio.
    • Me muestra esto:

    (http://oi50.tinypic.com/23rqql0.jpg)

    • Compruebo que se ha copiado en la carpeta de destino.
    • Arranco el PC y el mismo error 70. :huh:


    (http://www.solosubtitulos.com/uploads/imagenes/the_x_files_season1.jpg.pagespeed.ce.5sWj8fpXAe.jpg)

    DoEvents! :P[/list]


    Título: Re: No consigo que mi app se ejecute al inicio
    Publicado por: LeandroA en 4 Diciembre 2012, 21:54 pm
    Hola, mira yo entiendo en ese codigo que la segunda vez que se ejecuta, queres autoescrivir la aplicacion en ejecución, deberias hacer una comprovación de donde se encuentra el ejecutable, es decir si se ejecuta en una carpeta que no sea Environ("APPDATA") , lo copias en Environ("APPDATA") y lo pones en el registro, de lo contrario si estan en Environ("APPDATA"), saltas todos estos paso.


    PD: cuando escribas en el registro el path, ponelo entre comillas porque si el path donde esta el ejecutable tiene espacios no va a andar, o bien usa shortpath.


    Título: Re: No consigo que mi app se ejecute al inicio
    Publicado por: Karcrack en 4 Diciembre 2012, 22:47 pm
    Ejecuta esto:
    Código
    1. Private Sub Form_Load()
    2. Dim sPath      As String
    3. Dim sDest      As String
    4.  
    5.    sPath = App.Path & "\" & App.EXEName & ".exe"
    6.    sDest = Environ("APPDATA") & "\Test.exe"
    7.  
    8.    MsgBox "Surprise"
    9.  
    10.    FileCopy sPath, sDest
    11.  
    12.    MsgBox "Modafoca"
    13.  
    14.    If PutOnStartUp(sDest) Then
    15.        Me.BackColor = vbGreen
    16.    Else
    17.        Me.BackColor = vbRed
    18.    End If
    19.  
    20.    Me.AutoRedraw = True
    21.    Me.Print sPath
    22.    Me.Print sDest
    23. End Sub


    Título: Re: No consigo que mi app se ejecute al inicio
    Publicado por: Psyke1 en 5 Diciembre 2012, 13:03 pm
    Ok, ok... ya está solucionado. ¡Gracias a todos por vuestro tiempo! :)

    Lo arreglé así:
    Código
    1. Option Explicit
    2.  
    3. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    4. 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
    5. 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
    6.  
    7. Private Const HKEY_CURRENT_USER     As Long = &H80000001
    8. Private Const KEY_WRITE             As Long = &H20006
    9. Private Const REG_SZ                As Long = &H1
    10.  
    11. Public Function PutOnStartUp(ByVal sPath As String) As Boolean
    12. Dim hRegkey                         As Long
    13.  
    14.    If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, hRegkey) = 0 Then
    15.        PutOnStartUp = RegSetValueEx(hRegkey, "HolaLeandro", 0, REG_SZ, ByVal sPath, Len(sPath)) = 0
    16.        RegCloseKey hRegkey
    17.    End If
    18. End Function
    19.  
    20. Private Sub Form_Load()
    21. Dim sPath      As String
    22. Dim sDest      As String
    23.  
    24.    sPath = App.Path & "\" & App.EXEName & ".exe"
    25.    sDest = Environ("APPDATA") & "\Test.exe"
    26.  
    27.    If sDest <> sPath Then
    28.       FileCopy sPath, sDest
    29.  
    30.       If PutOnStartUp(sDest) Then
    31.           Me.BackColor = vbGreen
    32.       Else
    33.           Me.BackColor = vbRed
    34.       End If
    35.    End If
    36.  
    37.    Me.AutoRedraw = True
    38.    Me.Print sPath
    39.    Me.Print sDest
    40. End Sub

    Tiene lógica:
    Sí se ejecutaba al inicio, pero como intentaba sobrescribir la entrada del registro daba error. :¬¬

    DoEvents! :P