Modulo StartUp ["AutoRun.bas"] Falla

Iniciado por agus0, 5 Noviembre 2010, 02:17 AM

0 Miembros y 1 Visitante están viendo este tema.

agus0

Hola Gente Dando vueltas por Internet me encontré con este modulo que Creo que es de Leandro Ascierto. Y a la hora de usarlo Falla, pero me pareció averla usado antes. quería saber si alguien me puede corroborar si le funciona o no lo que pasa es que yo ahora cambie de S.O a W$7.

Gracias.

Código (vb) [Seleccionar]
Option Explicit

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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey& Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String)
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegDeleteValue& Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)

Private Const RAMA_RUN_WINDOWS As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F


Public Function SetAutoRun(Value As Boolean) As Boolean

    Dim Path          As String
    Dim Handle        As Long

    Path = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)

    RegOpenKeyEx HKEY_CURRENT_USER, RAMA_RUN_WINDOWS, 0, KEY_ALL_ACCESS, Handle
    If Value Then
        SetAutoRun = RegSetValueExString(Handle, App.Title, 0&, REG_SZ, Path, Len(Path)) = 0
    Else
        SetAutoRun = RegDeleteValue(Handle, App.Title) = 0
    End If
    RegCloseKey Handle

End Function


Public Function IsAutoRun() As Boolean

    Dim Path          As String
    Dim Handle        As Long
    Dim Data          As String
    Dim cch           As Long

    Path = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)

    RegOpenKeyEx HKEY_CURRENT_USER, RAMA_RUN_WINDOWS, 0, KEY_ALL_ACCESS, Handle
    RegQueryValueExNULL Handle, App.Title, 0&, 0&, 0&, cch

    If cch > 0 Then
        Data = String(cch - 1, 0)
        RegQueryValueExString Handle, App.Title, 0&, 0&, Data, cch
        IsAutoRun = Path = Data
    End If

    RegCloseKey Handle

End Function


_katze_

si iinicias tu aplicacion como administrador te tiene q funcionar ! igual creo q deberias buscar tu propia manera ya q como sabes desde W$ vista en adelante tenes el UAC y demas !

agus0

Buenas... Probé abriendo la aplicación como administrador y no funciono.
tengo mi manera de hacerlo pero esta me gusto mas... es mas corta jaja.
me parece no estoy seguro que la dirección donde se guarda en el inicio los programas que se cargan con Win7 no es igual al de los anteriores...

Gracias

raul338

#3
MM... ahora no tengo tiempo de fijarme, pero te dejo mi copia del modulo de leandro que si funciona, lo que pasa es que ahora la pagina de leandroA esta caida, siempre es bueno guardarse una copia offline xD

Código (vb) [Seleccionar]
Option Explicit
' http://www.leandroascierto.com.ar/categoria/M%C3%B3dulos/articulo/Inicio%20Aplicaci%C3%B3n%20con%20Windows.php
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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegSetValueExString Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As String, ByVal cbData As Long) As Long
Private Declare Function RegDeleteKey& Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As String)
Private Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As Long, lpcbData As Long) As Long
Private Declare Function RegQueryValueExString Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Private Declare Function RegDeleteValue& Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String)

Private Const RAMA_RUN_WINDOWS As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const REG_SZ As Long = 1
Private Const KEY_ALL_ACCESS = &H3F


Public Function SetAutoRun(value As Boolean) As Boolean

   Dim Path          As String
   Dim handle        As Long

   Path = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)

   RegOpenKeyEx HKEY_CURRENT_USER, RAMA_RUN_WINDOWS, 0, KEY_ALL_ACCESS, handle
   If value Then
       SetAutoRun = RegSetValueExString(handle, App.Title, 0&, REG_SZ, Path, Len(Path)) = 0
   Else
       SetAutoRun = RegDeleteValue(handle, App.Title) = 0
   End If
   RegCloseKey handle

End Function


Public Function IsAutoRun() As Boolean

   Dim Path          As String
   Dim handle        As Long
   Dim Data          As String
   Dim cch           As Long

   Path = Chr(34) & App.Path & "\" & App.EXEName & ".exe" & Chr(34)

   RegOpenKeyEx HKEY_CURRENT_USER, RAMA_RUN_WINDOWS, 0, KEY_ALL_ACCESS, handle
   RegQueryValueExNULL handle, App.Title, 0&, 0&, 0&, cch

   If cch > 0 Then
       Data = String(cch - 1, 0)
       RegQueryValueExString handle, App.Title, 0&, 0&, Data, cch
       IsAutoRun = Path = Data
   End If

   RegCloseKey handle

End Function

agus0

Gracias Raul. Si esta caída por desgracia :S ahora me voy a dormir mañana me fijo. Gracias!!

agus0

Raul, Mira probé el código y tampoco funciona, ejecute la App como admin y tampoco puede ser que W$7 Guarde las Claves de Inicio en otra parte del registro?

LeandroA

Hola ami en w7 me funciona bien, por las dudas como se llama tu proyecto, tiene espacios dentro del nombre?, en donde lo guardas, lo ejecutaste al menos una vez como para que se ejecute la linea SetAutoRun = true?

te fijaste si se escrivio en el registro en la clave
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

saludos.

raul338

A mi me funciona, me escribe en el registro :-\