如实现文件访问实时监控?
就是想知道谁(用户ID)在什么时间访问过什么文件,做了哪些操作,主要是打开,写入,改名,复制,移动和删除.
为公司做事,分不是问题!只要能解决,不够可再加.本人目前有10000分可用!

解决方案 »

  1.   

    ReadDirectoryChangesW
    注册监听目录FindFirstChangeNotification
    FindNextChangeNotification
    取出改变的文件名,修改方式为 新建,修改,删除GetUserName得到当前用户
      

  2.   

    忘了点东西
    FindFirstChangeNotification
    FindNextChangeNotification
    你要的功能它都能得到
      

  3.   

    http://www.vckbase.com/document/viewdoc.asp?id=814
      

  4.   

    监视一个目录
     
    来源:老侃第一站 作者:NowCan 添加时间:2003-03-12  
    关键字:监视目录  
          有关目录监视可能讨论过很多了,但大多使用FindFirstChangeNotification,FindCloseChangeNotification,FindNextChangeNotification这三个函数来做的,他们的问题是不能直接指出发生改变的文件名,而用ReadDirectoryChangesW就可以知道发生改变的文件名。
        这个程序可以监视一个目录中的任何变化,并指出发生改变的文件。但是还有一个小问题,就是处于监视下的目录中的任何文件都不能改名了,不知道为什么。
        程序贴过来的时候缩进没了,看起来费劲些,抱歉。
    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>typedef struct parm
    {
        char dir[128];
        HANDLE hDir;
    }THREAD_PARAM;DWORD WINAPI thread(LPVOID lParam)
    {
        THREAD_PARAM *Par=(THREAD_PARAM *)lParam;
        char notify[1024];
        FILE_NOTIFY_INFORMATION *pnotify=(FILE_NOTIFY_INFORMATION *)notify;
        char AnsiChar[3];
        wchar_t UnicodeChar[2];
        DWORD cbBytes;
        printf("Watch [%s] start.\n",Par->dir);
        while(true){
            if(ReadDirectoryChangesW(Par->hDir,&notify,sizeof(notify),true,
                FILE_NOTIFY_CHANGE_FILE_NAME|
                FILE_NOTIFY_CHANGE_DIR_NAME|
                FILE_NOTIFY_CHANGE_ATTRIBUTES|
                FILE_NOTIFY_CHANGE_SIZE|
                FILE_NOTIFY_CHANGE_LAST_WRITE|
                FILE_NOTIFY_CHANGE_LAST_ACCESS|
                FILE_NOTIFY_CHANGE_CREATION|
                FILE_NOTIFY_CHANGE_SECURITY,
                &cbBytes,
                NULL,
                NULL)){
                    switch(pnotify->Action){
                        case FILE_ACTION_ADDED:
                            printf("Directory/File added - ");
                            break;
                        case FILE_ACTION_REMOVED:
                            printf("Directory/File removed - ");
                            break;
                        case FILE_ACTION_MODIFIED:
                            printf("Directory/File modified - ");
                            break;
                        case FILE_ACTION_RENAMED_OLD_NAME:
                            printf("Directory/File old name - ");
                            break;
                        case FILE_ACTION_RENAMED_NEW_NAME:
                            printf("Directory/File new name - ");
                            break;
                    }
                    printf("%s",Par->dir);
                    for(DWORD i=0;i<pnotify->FileNameLength/2;i++){
                        UnicodeChar[0]=pnotify->FileName[i];
                        UnicodeChar[1]=0;
                        ZeroMemory(AnsiChar,3);
                        WideCharToMultiByte(CP_ACP,0,UnicodeChar,-1,AnsiChar,3,NULL,NULL);
                        printf("%s",AnsiChar);
                    }
                printf("\n");
                }
        }
    }int main(int argc,char **argv)
    {
    DWORD ThreadId;
    THREAD_PARAM Par;
    HANDLE hThread;
    if(argc!=2)
    {
    printf("DirWatch <Directory>\n");
    return 0;
    }
    lstrcpyn(Par.dir,argv[1],127);
    Par.hDir = CreateFile(
    Par.dir, // pointer to the file name
    FILE_LIST_DIRECTORY, // access (read/write) mode
    FILE_SHARE_READ|FILE_SHARE_DELETE, // share mode
    NULL, // security descriptor
    OPEN_EXISTING, // how to create
    FILE_FLAG_BACKUP_SEMANTICS, // file attributes
    NULL // file with attributes to copy
    );
    if(Par.hDir)
    {
    printf("Open Directory [%s] successfully.\n",Par.dir);}
    else
    {
    printf("Open Directory [%s] failed.\n",Par.dir);
    return 0;
    }
    hThread=CreateThread(NULL,0,thread,(LPVOID *)&Par,0,&ThreadId);
    if(hThread)
    {
    printf("CreateThread OK.\n");
    printf("Press <q> to quit.\n");
    while(getch()!='q');
    TerminateThread(hThread,0);
    WaitForSingleObject(hThread,1000);
    CloseHandle(Par.hDir);
    }
    else
    {
    printf("CreateThread failed, the program exit.\n");
    }}
       
     
      

  5.   

    我主要想知道谁改变了文件,得到他的Username!
    主要应用在文件服务器上!
    有什么好的方法吗?
      

  6.   

    好象只能做一个客户端的程序才能知道Username
      

  7.   


    连着发了三个帖子
    后来找到了源代码
    想再往上帖时却告之连续贴子的只能有三个
    呵呵
    不爽http://www.vckbase.com/code/downcode.asp?id=2073
    楼上的已经帖出来了不知你有没有注意到windows管理->系统工具->共享文件夹->打开文件
    在那里就能知道哪个用户在访问
    但实现可不会
    帮你找找吧
      

  8.   

    To 888atao(阿涛):
    不知你有没有注意到windows管理->系统工具->共享文件夹->打开文件
      

  9.   

    To 888atao(阿涛):
    不知你有没有注意到windows管理->系统工具->共享文件夹->打开文件
    ==============================
    我也想到了这里,但不知怎么实现.
    DX们帮帮忙!!!