500分求一问题解决 (来提供方案的都有份啊) ( 积分: 300 )

  • 主题发起人 主题发起人 形单影只
  • 开始时间 开始时间

形单影只

Unregistered / Unconfirmed
GUEST, unregistred user!
监视本地移动存储器(U盘、A盘)上的文件创建、更名、修改、删除。<br>设置内容:允许、禁止访问U盘(默认允许);<br>允许、禁止访问A盘(默认允许);<br>一贴最多300分,若解决再开贴加分<br>
 
监视本地移动存储器(U盘、A盘)上的文件创建、更名、修改、删除。<br>设置内容:允许、禁止访问U盘(默认允许);<br>允许、禁止访问A盘(默认允许);<br>一贴最多300分,若解决再开贴加分<br>
 
500 先google
 
要是google的到答案就不用问了,和不在这里解答了,以后的人也可以google的到了,造福人类,哈哈
 
占个位置先
 
以前做delphi的高人现在都转行啦?
 
我也占个位置,学习学习!
 
我要想知道......
 
实现对已经存在的盘监视已经实现,但问题是a盘没法监视,除非a盘里面有盘,不然无法得到正确的句柄,谁知道如何或者a盘中有盘的信息?如果做定时器去检测可能太耗资源了,因为a盘会一直响应,下面是一部分实现的代码<br>//监控目录<br>procedure tform1.jkmu(path:string);<br>begin<br> &nbsp;FNotifyFilter := 0;<br> FNotifyFilter:=<br> FILE_NOTIFY_CHANGE_FILE_NAME or<br> FILE_NOTIFY_CHANGE_DIR_NAME or<br> FILE_NOTIFY_CHANGE_ATTRIBUTES or<br> FILE_NOTIFY_CHANGE_SIZE or<br> FILE_NOTIFY_CHANGE_LAST_WRITE &nbsp;or<br> FILE_NOTIFY_CHANGE_LAST_ACCESS or<br> FILE_NOTIFY_CHANGE_CREATION or<br> FILE_NOTIFY_CHANGE_SECURITY;<br> &nbsp;if FNotifyFilter = 0 then<br> &nbsp;begin<br> &nbsp; &nbsp; exit;<br> &nbsp;end;<br><br> &nbsp;FDirectoryHandle := CreateFile(PChar(path),<br> &nbsp; &nbsp;FILE_LIST_DIRECTORY,<br> &nbsp; &nbsp;FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,<br> &nbsp; &nbsp;nil,<br> &nbsp; &nbsp;OPEN_EXISTING,<br> &nbsp; &nbsp;FILE_FLAG_BACKUP_SEMANTICS or FILE_FLAG_OVERLAPPED,<br> &nbsp; &nbsp;0);<br> &nbsp;if FDirectoryHandle = INVALID_HANDLE_VALUE then<br> &nbsp;begin<br> &nbsp; &nbsp;beep;<br> &nbsp; &nbsp;FDirectoryHandle := 0;<br> &nbsp; &nbsp;ShowMessage(SysErrorMessage(GetLastError));<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br> &nbsp;FCompletionPort := CreateIoCompletionPort(FDirectoryHandle, 0, Longint(pointer(self)), 0);<br> &nbsp;ZeroMemory(@FNotificationBuffer, SizeOf(FNotificationBuffer));<br> &nbsp;FBytesWritten := 0;<br> &nbsp;if not ReadDirectoryChanges(FDirectoryHandle, @FNotificationBuffer,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SizeOf(FNotificationBuffer), true,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FNotifyFilter, @FBytesWritten, @FOverlapped, nil) then<br> &nbsp;begin<br> &nbsp; &nbsp;CloseHandle(FDirectoryHandle);<br> &nbsp; &nbsp;FDirectoryHandle := 0;<br> &nbsp; &nbsp;CloseHandle(FCompletionPort);<br> &nbsp; &nbsp;FCompletionPort := 0;<br> &nbsp; &nbsp;ShowMessage(SysErrorMessage(GetLastError));<br> &nbsp; &nbsp;exit;<br> &nbsp;end;<br><br> &nbsp;FWatchThread := TWaitThread.Create(self);<br> &nbsp;TWaitThread(FWatchThread).Resume;<br>end;<br>//停止监控目录<br>procedure tform1.stopjkmu();<br>begin<br>if FCompletionPort = 0 then<br> &nbsp; &nbsp;exit;<br> &nbsp;PostQueuedCompletionStatus(FCompletionPort, 0, 0, nil);<br> &nbsp;FWatchThread.WaitFor;<br> &nbsp;FWatchThread.Free;<br> &nbsp;CloseHandle(FDirectoryHandle);<br> &nbsp;FDirectoryHandle := 0;<br> &nbsp;CloseHandle(FCompletionPort);<br> &nbsp;FCompletionPort := 0;<br>end;<br><br>constructor TWaitThread.Create(Form: TForm1);<br>begin<br> &nbsp;inherited Create(True);<br> &nbsp;FForm := Form;<br> &nbsp;FreeOnTerminate := False;<br>end;<br><br>procedure TWaitThread.HandleEvent;<br>var<br> &nbsp;FileOpNotification: PFileNotifyInformation;<br> &nbsp;Offset: Longint;<br>begin<br> &nbsp;with FForm do<br> &nbsp;begin<br> &nbsp; &nbsp;Pointer(FileOpNotification) := @FNotificationBuffer[0];<br> &nbsp; &nbsp;repeat<br> &nbsp; &nbsp; &nbsp;Offset := FileOpNotification^.NextEntryOffset;<br> &nbsp; &nbsp; &nbsp;writelog(<br> &nbsp; &nbsp; &nbsp;Format(SAction[FileOpNotification^.Action],<br> &nbsp; &nbsp; &nbsp;[WideCharToString(@(FileOpNotification^.FileName))])<br> &nbsp; &nbsp; &nbsp;,'wjjk');<br> &nbsp; &nbsp; &nbsp;PChar(FileOpNotification) := PChar(FileOpNotification)+Offset;<br> &nbsp; &nbsp;until Offset=0;<br> &nbsp;end;<br>end;<br><br>procedure TWaitThread.Execute;<br>var<br> &nbsp;numBytes: DWORD;<br> &nbsp;cbOffset: DWORD;<br> &nbsp;CompletionKey: DWORD;<br>begin<br> &nbsp;while not Terminated do<br> &nbsp;begin<br> &nbsp; &nbsp;GetQueuedCompletionStatus( FForm.FCompletionPort, numBytes, CompletionKey, FForm.FPOverlapped, INFINITE);<br> &nbsp; &nbsp;if CompletionKey &amp;lt;&amp;gt; 0 then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;Synchronize(HandleEvent);<br> &nbsp; &nbsp; &nbsp;with FForm do<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;FBytesWritten := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp;ZeroMemory(@FNotificationBuffer, SizeOf(FNotificationBuffer));<br> &nbsp; &nbsp; &nbsp; &nbsp;ReadDirectoryChanges(FDirectoryHandle, @FNotificationBuffer, SizeOf(FNotificationBuffer), true, FNotifyFilter, @FBytesWritten, @FOverlapped, nil);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;Terminate;<br> &nbsp;end;<br>end;
 
后退
顶部