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

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Cómo detectar mediante la Api cambios en la información del disco duro.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Cómo detectar mediante la Api cambios en la información del disco duro.  (Leído 7,424 veces)
sch3m4
Ex-Staff
*
Desconectado Desconectado

Mensajes: 1.608

Nihil est in intelectu quod prius not fuerit insen


Ver Perfil WWW
Re: Cómo detectar mediante la Api cambios en la información del disco duro.
« Respuesta #10 en: 1 Agosto 2005, 02:20 am »

he retocado l codigo para k haga lo miso que haces tú con VB, pero tampoco funciona. El código en VB que posteastes tampoco me funciona. Aquí dejo el código en C

Código:
#include <stdio.h>
#include <windows.h>

#define COMPLETO FILE_NOTIFY_CHANGE_ATTRIBUTES || FILE_NOTIFY_CHANGE_DIR_NAME || FILE_NOTIFY_CHANGE_FILE_NAME || FILE_NOTIFY_CHANGE_SIZE || FILE_NOTIFY_CHANGE_LAST_WRITE || FILE_NOTIFY_CHANGE_SECURITY

/*FUNCIÓN PRINCIPAL*/
void main()
{
//devuelde la descripción del error, a partir de su código
char *MensajeError(DWORD error_num);
HANDLE mon1;

mon1=FindFirstChangeNotification("C:\\",TRUE,COMPLETO);
WaitForSingleObject(mon1,1);

//creamos el handle
if(mon1==INVALID_HANDLE_VALUE)
{
printf("[!] Error al crear el handle -> %s",MensajeError(GetLastError()));
return;
}

for(;;)
{
FindNextChangeNotification(mon1);
if(WaitForSingleObject(mon1,1)==0)
{
printf("\nLa informacion en la unidad C:\\ ha cambiado");
}

Sleep(1000);
}

//cerramos y salimos
FindCloseChangeNotification(mon1);
return;
}

//devuelde la descripción del error, a partir de su código
char *MensajeError(DWORD error_num)
{
char *lpMsgBuf;

//cojemos el mensaje del error
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error_num,
0,
(LPTSTR) &lpMsgBuf,
0,
NULL
);

return lpMsgBuf;
}


En línea

SafetyBits

"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.(..
goodbye

Desconectado Desconectado

Mensajes: 93



Ver Perfil
Re: Cómo detectar mediante la Api cambios en la información del disco duro.
« Respuesta #11 en: 1 Agosto 2005, 07:22 am »

Será la Api WaitForSingleObject

Honestamente a mi me funciona someramente.

Debería ser así WaitForSingleObject Handle, &HFFFFFFFF

pero con este valor infinito se congela.  :(

Me dí cuenta que cuando ocurre el evento WaitForSingleObject devuelve 0. Entonces lo que estoy tratando de hacer es mantenerla sin que se congele pero al mismo tiempo que este pediente del proceso.

Citar
El código en VB que posteastes tampoco me funciona.

No puedo decir que sea perfecto  :-\ pero el evento se verificará en algún momento.
Quizás no sea la manera adecuada, preguntémosle nuevamente a los que más saben.

Por último me gustaría volver a citar a Anhur y fíjense en lo que dice: 'luego en un bucle a la segunda'

Citar
Las funciones son FindFirstChangeNotification y FindNextChangeNotification. Primero se llama a la primera función y luego en un bucle a la segunda.

Saludos.


« Última modificación: 1 Agosto 2005, 08:16 am por CrackelDestripador » En línea

Al lado de la dificultad está la facilidad.
Cambiad de placeres, pero no cambies de amigos.
Aceptar un favor de un amigo, es hacerle otro.
Slasher-K


Desconectado Desconectado

Mensajes: 1.477


Ver Perfil
Re: Cómo detectar mediante la Api cambios en la información del disco duro.
« Respuesta #12 en: 2 Agosto 2005, 00:45 am »

El siguiente ejemplo funciona perfectamente.

Código:
Option Explicit

Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4
Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const FILE_NOTIFY_CHANGE_SIZE = &H8
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10
Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100
Private Const INFINITE = &HFFFFFFFF
Private Const OBJECT_WAIT_0 = 0
Private Const INVALID_HANDLE_VALUE = -1

Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

Private bFileMonEnabled As Boolean

Sub Main()
  Call StartFileMon
  Call frmMain.Show
End Sub

Sub FileMonProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
        Dim r&, hMon&

  r = KillTimer(0&, idEvent)
 
  bFileMonEnabled = True
  hMon = FindFirstChangeNotification("C:\WINDOWS", True, FILE_NOTIFY_CHANGE_ALL)
 
  Do While bFileMonEnabled
    r = WaitForSingleObject(hMon, 100&)
   
    If r = OBJECT_WAIT_0 Then
      r = FindNextChangeNotification(hMon)
     
      'Se modificó el directorio.
      '
    End If
   
    DoEvents
  Loop
 
  r = FindCloseChangeNotification(hMon)
End Sub

Sub StartFileMon()
  If Not bFileMonEnabled Then
    Call SetTimer(0&, 0&, 0&, AddressOf FileMonProc)
  End If
End Sub

Sub StopFileMon()
  bFileMonEnabled = False
End Sub

Lympex, tu error es que se debe llamar a FindNextChangeNotification luego de que la función WaitForSingleObject devuelva OBJECT_WAIT_0. Lo que hace es reestablecer el objeto a non-signaled.

Saludos.
En línea



A la reina de las profundidades que cuida los pasos de una sombra en la noche :*
Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines