elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [Source] Reniciar la aplicacion ante un Error
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Source] Reniciar la aplicacion ante un Error  (Leído 2,142 veces)
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
[Source] Reniciar la aplicacion ante un Error
« en: 28 Diciembre 2009, 04:35 am »

Este es un modulo bas para Reiniciar la aplicación si es que aparece un error y no fue controlado  (No errores de sistemas esos que aparece el maldito boton"No Enviar") sino los comunes de vb

Código:
Option Explicit
'Autor: Leandro Ascierto
'Web:   www.leandroascierto.com.ar
'Date:  28/12/2009
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function CreateWindowEx Lib "user32.dll" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
Private Declare Function DestroyWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function SetProp Lib "user32.dll" Alias "SetPropA" (ByVal hwnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Sub FatalExit Lib "kernel32" (ByVal code As Long)

Dim hWinStatic As Long
Dim AppPath As String
Dim LastError As Long

Private Function CallSomeFunction()
    'No borrar esta linea
End Function

Public Sub StarProtect()
    hWinStatic = CreateWindowEx(0, "Static", "WindowControlerCrash", 0, 0, 0, 0, 0, 0, 0, 0, 0&)
    AppPath = GetAppPath
    SetTimer hWinStatic, 0, 100, AddressOf TimerProc
End Sub

Public Sub EndProtect()
    KillTimer hWinStatic, 0
    DestroyWindow hWinStatic
End Sub

Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    Dim Ret As String
   
    If Err.Number = 40040 Then
        ShellExecute hWinStatic, vbNullString, AppPath, LastError, vbNullString, 1
        FatalExit 1
    Else
        LastError = Err.Number
        Ret = CallSomeFunction
    End If
   
End Sub

Private Function GetAppPath() As String
    Dim ModuleName As String
    Dim Ret As Long
    ModuleName = String$(255, Chr$(0))
    Ret = GetModuleFileName(App.hInstance, ModuleName, 255)
    GetAppPath = Left$(ModuleName, Ret)
End Function

Para probarlo en un formulario con Tres botones

Código:
Option Explicit

Private Sub Form_Load()
    If Command$ <> "" Then Me.Caption = "Aplicación Reinciada por error: " & Command$
    StarProtect 'comienza la protección
End Sub

Private Sub Form_Unload(Cancel As Integer)
    EndProtect 'Detiene la protección
End Sub


Private Sub Command1_Click()
    MsgBox 1 / 0 'Error Divición por cero
End Sub

Private Sub Command2_Click()
    Dim i As Integer
    i = 8000000000000# 'Error Desvordamiento
End Sub

Private Sub Command3_Click()
    Dim c As Date
    c = "hola" 'Error no coinciden los tipos
End Sub

Lo compilan y verán que al producir un error la aplicacion se reinicia.

Saludos.


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [Source] Reniciar la aplicacion ante un Error
« Respuesta #1 en: 28 Diciembre 2009, 05:49 am »

Lo he probado y funciona bien!¡.

Por hay solo de de obtener el handle de una ventana creada con api de igual forma se puede quitar y pasarle un handle 0, aun que aun asi esta bueno

Ducles Lunas!¡.


En línea

The Dark Shadow is my passion.
ssccaann43 ©


Desconectado Desconectado

Mensajes: 792


¬¬


Ver Perfil
Re: [Source] Reniciar la aplicacion ante un Error
« Respuesta #2 en: 28 Diciembre 2009, 16:05 pm »

Excelente Leandro!
En línea

- Miguel Núñez
Todos tenemos derechos a ser estupidos, pero algunos abusan de ese privilegio...
"I like ^TiFa^"
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Error ante un submit
PHP
Zinc 7 2,689 Último mensaje 25 Octubre 2012, 09:44 am
por RevangelyonX
[Source]Aplicacion google hacking
Programación Visual Basic
wizardsec 0 1,291 Último mensaje 20 Febrero 2015, 05:00 am
por wizardsec
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines