Autor
|
Tema: Cómo detectar mediante la Api cambios en la información del disco duro. (Leído 7,457 veces)
|
sch3m4
Ex-Staff
Desconectado
Mensajes: 1.608
Nihil est in intelectu quod prius not fuerit insen
|
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 #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
Mensajes: 93
|
Será la Api WaitForSingleObjectHonestamente a mi me funciona someramente. Debería ser así WaitForSingleObject Handle, &HFFFFFFFFpero 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. 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'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
Mensajes: 1.477
|
El siguiente ejemplo funciona perfectamente. 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 :*
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Problemon: al conectar hd a android mediante base usb me daño el disco duro
Hardware
|
mouth
|
0
|
2,100
|
10 Agosto 2013, 12:48 pm
por mouth
|
|
|
¿Cómo detectar cambios en .text?
« 1 2 »
Programación C/C++
|
Shout
|
11
|
5,802
|
1 Octubre 2014, 22:38 pm
por Eternal Idol
|
|
|
¿Fuego? ¿Martillazos? Cómo destruir un disco duro sin dejar información ...
Noticias
|
wolfbcn
|
0
|
1,126
|
4 Enero 2016, 02:43 am
por wolfbcn
|
|
|
Como detectar cambios en un listbox en tiempo de ejecución
Programación Visual Basic
|
rapbyone
|
1
|
2,544
|
20 Agosto 2016, 04:55 am
por Eleкtro
|
|
|
Las interferencias mediante ultrasonidos pueden bloquear un disco duro
Noticias
|
wolfbcn
|
1
|
1,223
|
30 Mayo 2018, 00:04 am
por Machacador
|
|