如何记录下WINDOWS的文件操作[比如什么时候创建、删除或修改一个文件]? ( 积分: 200 )

  • 主题发起人 主题发起人 dkzhuang
  • 开始时间 开始时间
D

dkzhuang

Unregistered / Unconfirmed
GUEST, unregistred user!
如何对网络共享盘操作?除上述功能我还需要对文件操作的用户IP。
 
如何对网络共享盘操作?除上述功能我还需要对文件操作的用户IP。
 
系统的HOOK可做到的
 
比较复杂,可以参考windows核心编程一书
 
陈省编的Delphi 深度探索(第二版)里有。
 
我正好有一个例子,你看看吧,要源码就留EMAIL<br>unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, StdCtrls, Shlobj, Activex, TFlatMemoUnit, TFlatSpeedButtonUnit,<br> &nbsp;TFlatAnimWndUnit, TFlatTitlebarUnit;<br><br>const<br> &nbsp; &nbsp;SHCNE_RENAMEITEM = $1;<br> &nbsp; &nbsp;SHCNE_CREATE = $2;<br> &nbsp; &nbsp;SHCNE_DELETE = $4;<br> &nbsp; &nbsp;SHCNE_MKDIR = $8;<br> &nbsp; &nbsp;SHCNE_RMDIR = $10;<br> &nbsp; &nbsp;SHCNE_MEDIAINSERTED = $20;<br> &nbsp; &nbsp;SHCNE_MEDIAREMOVED = $40;<br> &nbsp; &nbsp;SHCNE_DRIVEREMOVED = $80;<br> &nbsp; &nbsp;SHCNE_DRIVEADD = $100;<br> &nbsp; &nbsp;SHCNE_NETSHARE = $200;<br> &nbsp; &nbsp;SHCNE_NETUNSHARE = $400;<br> &nbsp; &nbsp;SHCNE_ATTRIBUTES = $800;<br> &nbsp; &nbsp;SHCNE_UPDATEDIR = $1000;<br> &nbsp; &nbsp;SHCNE_UPDATEITEM = $2000;<br> &nbsp; &nbsp;SHCNE_SERVERDISCONNECT = $4000;<br> &nbsp; &nbsp;SHCNE_UPDATEIMAGE = $8000;<br> &nbsp; &nbsp;SHCNE_DRIVEADDGUI = $10000;<br> &nbsp; &nbsp;SHCNE_RENAMEFOLDER = $20000;<br> &nbsp; &nbsp;SHCNE_FREESPACE = $40000;<br> &nbsp; &nbsp;SHCNE_ASSOCCHANGED = $8000000;<br> &nbsp; &nbsp;SHCNE_DISKEVENTS = $2381F;<br> &nbsp; &nbsp;SHCNE_GLOBALEVENTS = $C0581E0;<br> &nbsp; &nbsp;SHCNE_ALLEVENTS = $7FFFFFFF;<br> &nbsp; &nbsp;SHCNE_INTERRUPT = $80000000;<br> &nbsp; &nbsp;SHCNF_IDLIST = 0;<br> &nbsp; &nbsp;// LPITEMIDLIST<br> &nbsp; &nbsp;SHCNF_PATHA = $1;<br> &nbsp; &nbsp;// path name<br> &nbsp; &nbsp;SHCNF_PRINTERA = $2;<br> &nbsp; &nbsp;// printer friendly name<br> &nbsp; &nbsp;SHCNF_DWORD = $3;<br> &nbsp; &nbsp;// DWORD<br> &nbsp; &nbsp;SHCNF_PATHW = $5;<br> &nbsp; &nbsp;// path name<br> &nbsp; &nbsp;SHCNF_PRINTERW = $6;<br> &nbsp; &nbsp;// printer friendly name<br> &nbsp; &nbsp;SHCNF_TYPE = $FF;<br> &nbsp; &nbsp;SHCNF_FLUSH = $1000;<br> &nbsp; &nbsp;SHCNF_FLUSHNOWAIT = $2000;<br> &nbsp; &nbsp;SHCNF_PATH = SHCNF_PATHW;<br> &nbsp; &nbsp;SHCNF_PRINTER = SHCNF_PRINTERW;<br> &nbsp; &nbsp;WM_SHNOTIFY = $401;<br> &nbsp; &nbsp;NOERROR = 0;<br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Memo1: TFlatMemo;<br> &nbsp; &nbsp;FlatSBRegister: TFlatSpeedButton;<br> &nbsp; &nbsp;FlatSBUnRegister: TFlatSpeedButton;<br> &nbsp; &nbsp;FlatSBSave: TFlatSpeedButton;<br> &nbsp; &nbsp;FlatSBQuit: TFlatSpeedButton;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> &nbsp; &nbsp;procedure FlatSBRegisterClick(Sender: TObject);<br> &nbsp; &nbsp;procedure FlatSBUnRegisterClick(Sender: TObject);<br> &nbsp; &nbsp;procedure FlatSBQuitClick(Sender: TObject);<br> &nbsp; &nbsp;procedure FlatSBSaveClick(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;procedure WMShellReg(var Msg : TMessage); Message WM_SHNOTIFY;<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br> &nbsp;<br> &nbsp;type PSHNOTIFYSTRUCT=^SHNOTIFYSTRUCT;<br> &nbsp; &nbsp;SHNOTIFYSTRUCT = record<br> &nbsp; &nbsp;dwItem1 : PItemIDList;<br> &nbsp; &nbsp;dwItem2 : PItemIDList;<br> &nbsp;end;<br><br> &nbsp;Type PSHFileInfoByte=^SHFileInfoByte;<br> &nbsp; &nbsp;_SHFileInfoByte = record<br> &nbsp; &nbsp;hIcon :Integer;<br> &nbsp; &nbsp;iIcon :Integer;<br> &nbsp; &nbsp;dwAttributes : Integer;<br> &nbsp; &nbsp;szDisplayName : array [0..259] of char;<br> &nbsp; &nbsp;szTypeName : array [0..79] of char;<br> &nbsp;end;<br><br> &nbsp;SHFileInfoByte=_SHFileInfoByte;<br><br> &nbsp;Type PIDLSTRUCT = ^IDLSTRUCT;<br> &nbsp; &nbsp; _IDLSTRUCT = record<br> &nbsp; &nbsp; pidl : PItemIDList;<br> &nbsp; &nbsp; bWatchSubFolders : Integer;<br> &nbsp;end;<br> &nbsp;IDLSTRUCT =_IDLSTRUCT;<br><br> &nbsp;function SHNotify_Register(hWnd : Integer) : Bool;<br> &nbsp;function SHNotify_UnRegister:Bool;<br> &nbsp;function SHEventName(strPath1,strPath2:string;lParam:Integer):string;<br> &nbsp;Function SHChangeNotifyDeregister(hNotify:integer):integer;stdcall; &nbsp;external 'Shell32.dll' index 4;<br> &nbsp;Function SHChangeNotifyRegister(hWnd,uFlags,dwEventID,uMSG,cItems:LongWord;<br> &nbsp;lpps:PIDLSTRUCT):integer;stdcall;external 'Shell32.dll' index 2;<br> &nbsp;Function SHGetFileInfoPidl(pidl : PItemIDList;<br> &nbsp;dwFileAttributes : Integer;<br> &nbsp;psfib : PSHFILEINFOBYTE;<br> &nbsp;cbFileInfo : Integer;<br> &nbsp;uFlags : Integer):Integer;stdcall;<br> &nbsp;external 'Shell32.dll' name 'SHGetFileInfoA';<br>var<br> &nbsp;Form1: TForm1;<br> &nbsp;m_hSHNotify : Integer;<br> &nbsp;m_pidlDesktop : PItemIDList;<br>implementation<br><br>{$R *.dfm}<br>function SHEventName(strPath1,strPath2:string;lParam:Integer):string;<br>var<br> &nbsp;sEvent:String;<br>begin<br> &nbsp; &nbsp;case lParam of //根据参数设置提示消息<br> &nbsp; &nbsp;SHCNE_RENAMEITEM: sEvent := '重命名文件'+strPath1+'为'+strpath2;<br> &nbsp; &nbsp;SHCNE_CREATE: sEvent := '建立文件 文件名:'+strPath1;<br> &nbsp; &nbsp;SHCNE_DELETE: sEvent := '删除文件 文件名:'+strPath1;<br> &nbsp; &nbsp;SHCNE_MKDIR: sEvent := '新建目录 目录名:'+strPath1;<br> &nbsp; &nbsp;SHCNE_RMDIR: sEvent := '删除目录 目录名:'+strPath1;<br> &nbsp; &nbsp;SHCNE_MEDIAINSERTED: sEvent := strPath1+'中插入可移动存储介质';<br> &nbsp; &nbsp;SHCNE_MEDIAREMOVED: sEvent := strPath1+'中移去可移动存储介质'+strPath1+' '+strpath2;<br> &nbsp; &nbsp;SHCNE_DRIVEREMOVED: sEvent := '移去驱动器'+strPath1;<br> &nbsp; &nbsp;SHCNE_DRIVEADD: sEvent := '添加驱动器'+strPath1;<br> &nbsp; &nbsp;SHCNE_NETSHARE: sEvent := '改变目录'+strPath1+'的共享属性';<br> &nbsp; &nbsp;SHCNE_ATTRIBUTES: sEvent := '改变文件目录属性 文件名'+strPath1;<br> &nbsp; &nbsp;SHCNE_UPDATEDIR: sEvent := '更新目录'+strPath1;<br> &nbsp; &nbsp;SHCNE_UPDATEITEM: sEvent := '更新文件 文件名:'+strPath1;<br> &nbsp; &nbsp;SHCNE_SERVERDISCONNECT: sEvent := '断开与服务器的连接'+strPath1+' '+strpath2;<br> &nbsp; &nbsp;SHCNE_UPDATEIMAGE: sEvent := 'SHCNE_UPDATEIMAGE';<br> &nbsp; &nbsp;SHCNE_DRIVEADDGUI: sEvent := 'SHCNE_DRIVEADDGUI';<br> &nbsp; &nbsp;SHCNE_RENAMEFOLDER: sEvent := '重命名文件夹'+strPath1+'为'+strpath2;<br> &nbsp; &nbsp;SHCNE_FREESPACE: sEvent := '磁盘空间大小改变';<br> &nbsp; &nbsp;SHCNE_ASSOCCHANGED: sEvent := '改变文件关联';<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp;sEvent:='未知操作'+IntToStr(lParam);<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;Result:=sEvent;<br>end;<br><br><br>function SHNotify_Register(hWnd : Integer) : Bool;<br>var<br>// ps:PIDLSTRUCT;<br> ps : _IDLSTRUCT;<br>begin<br>{$R-}<br> &nbsp;Result:=False;<br> &nbsp;If m_hSHNotify = 0 then begin<br> &nbsp;//获取桌面文件夹的Pidl<br> &nbsp;if SHGetSpecialFolderLocation(0, CSIDL_DESKTOP,m_pidlDesktop) &lt;&gt; NOERROR then<br> &nbsp;Form1.close;<br> &nbsp;if Boolean(m_pidlDesktop) then begin<br> &nbsp;ps.bWatchSubFolders := 1;<br> &nbsp;ps.pidl := m_pidlDesktop;<br> &nbsp;// 利用SHChangeNotifyRegister函数注册系统消息处理<br> &nbsp;m_hSHNotify := SHChangeNotifyRegister(hWnd, (SHCNF_TYPE Or SHCNF_IDLIST),<br> &nbsp;(SHCNE_ALLEVENTS Or SHCNE_INTERRUPT),<br> &nbsp;WM_SHNOTIFY, 1, @ps);<br> &nbsp;Result := Boolean(m_hSHNotify);<br> &nbsp;end<br> &nbsp;Else<br> &nbsp;// 如果出现错误就使用 CoTaskMemFree函数来释放句柄<br> &nbsp;CoTaskMemFree(m_pidlDesktop);<br>End;<br>{$R+}<br>end;<br><br>function SHNotify_UnRegister:Bool;<br>begin<br> &nbsp;Result:=False;<br> &nbsp;If Boolean(m_hSHNotify) Then<br> &nbsp;//取消系统消息监视,同时释放桌面的Pidl<br> &nbsp;If Boolean(SHChangeNotifyDeregister(m_hSHNotify)) Then<br> &nbsp;begin<br> &nbsp; {$R-}<br> &nbsp; &nbsp;m_hSHNotify := 0;<br> &nbsp; &nbsp;CoTaskMemFree(m_pidlDesktop);<br> &nbsp; &nbsp;Result := True;<br> &nbsp; {$R-}<br> &nbsp;End;<br>end;<br><br>procedure TForm1.WMShellReg(var Msg:TMessage); //系统消息处理函数<br>var<br> &nbsp;strPath1,strPath2 : String;<br> &nbsp;charPath :array[0..259]of char;<br> &nbsp;pidlItem : PSHNOTIFYSTRUCT;<br>begin<br> &nbsp; pidlItem:=PSHNOTIFYSTRUCT(Msg.wParam);<br> &nbsp; &nbsp;//获得系统消息相关得路径<br> &nbsp; SHGetPathFromIDList(pidlItem.dwItem1,charPath);<br> &nbsp; strPath1:=charPath;<br> &nbsp; SHGetPathFromIDList(pidlItem.dwItem2,charPath);<br> &nbsp; strPath2:=charPath;<br> &nbsp; Memo1.Lines.Add(SHEvEntName(strPath1,strPath2,Msg.lParam));<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> &nbsp;if Boolean(m_pidlDesktop) then<br> &nbsp; &nbsp;SHNotify_Unregister;<br>end;<br><br>procedure TForm1.FlatSBRegisterClick(Sender: TObject);<br>begin<br> &nbsp;m_hSHNotify:=0;<br> &nbsp;if SHNotify_Register(Form1.Handle) then begin //注册Shell监视<br> &nbsp;Application.MessageBox('Shell监视程序成功注册!', '信息', 0);<br> &nbsp;FlatSBRegister.Enabled := False;<br> &nbsp;end<br> &nbsp;else<br> &nbsp;Application.MessageBox('Shell监视程序注册失败!', '信息', 0);<br>end;<br><br>procedure TForm1.FlatSBUnRegisterClick(Sender: TObject);<br>begin<br> if Boolean(m_pidlDesktop) then<br> &nbsp;SHNotify_Unregister;<br> FlatSBRegister.Enabled := True; <br>end;<br><br>procedure TForm1.FlatSBQuitClick(Sender: TObject);<br>begin<br> &nbsp;Close();<br>end;<br><br>procedure TForm1.FlatSBSaveClick(Sender: TObject);<br>begin<br> &nbsp;Memo1.Lines.SaveToFile('c:/tmp.txt'); <br>end;<br><br>end.
 
To app2001:<br> &nbsp;这个文件夹的问题已经基本解决了,再深层问一下。<br> 如何对网络共享盘操作?除上述功能我还需要登录的用户IP。<br> 简单的说就是谁对文件或文件夹进行怎样的操作。
 
这个就有等于你的慢慢研究了,这方面我了解的就不多了
 
后退
顶部