如何知道网络上谁在操作我的共享目录里的文件?象lockdown的功能一样? 等待答案!e-mail : [email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #pragma hdrstop //如果是VC的话,去掉这三行#include <condefs.h>#pragma argsused#include <windows.h>#include <stdio.h>#include <windef.h>#include <lmcons.h>#include <lmshare.h>#include <time.h>#include <conio.h>#include <string.h>USERES("nowcan.res"); //如果是VC的话,去掉这一行//---------------------------------------------------------------------------typedef DWORD (WINAPI *SVR_NETSESSIONENUM)(const char FAR *pszServer, short sLevel, char FAR *pbBuffer, unsigned short cbBuffer, unsigned short FAR * pcEntriesRead, unsigned short FAR * pcTotalAvail);struct session_info_50 { char FAR * sesi50_cname; //remote computer name (connection id in Netware) char FAR * sesi50_username; unsigned long sesi50_key; // used to delete session (not used in Netware) unsigned short sesi50_num_conns; unsigned short sesi50_num_opens; //not available in Netware unsigned long sesi50_time; unsigned long sesi50_idle_time; //not available in Netware unsigned char sesi50_protocol; unsigned char pad1;}; /* session_info_50 */struct parm{char dirt[128];FILE *fp;};SVR_NETSESSIONENUM pSVRNetSessionEnum;HANDLE ghDll_SvrApi;DWORD WINAPI thread(LPVOID lParam){//DWORD dwWaitStatus; HANDLE dwChangeHandle; time_t timer;struct tm *tblock;char dir[128];session_info_50 *psinfo;WORD ent,t_ent;strcpy(dir,((struct parm *)lParam)->dirt);dwChangeHandle=FindFirstChangeNotification(dir, true,FILE_NOTIFY_CHANGE_FILE_NAME| FILE_NOTIFY_CHANGE_DIR_NAME| FILE_NOTIFY_CHANGE_ATTRIBUTES| FILE_NOTIFY_CHANGE_SIZE| FILE_NOTIFY_CHANGE_LAST_WRITE);if(dwChangeHandle==INVALID_HANDLE_VALUE) { printf("ERROR!!!\n"); return(0); }printf("Watch [%s] ready.\n",dir);while(true) {// dwWaitStatus= WaitForSingleObject(dwChangeHandle,-1); timer = time(NULL); psinfo=(struct session_info_50 *) malloc(16384); pSVRNetSessionEnum(NULL, 50, (char *)psinfo, 16384,&ent,&t_ent); tblock = localtime(&timer); if(psinfo->sesi50_num_conns) { printf("[%04d-%02d-%02d %02d:%02d:%02d]: Something changed in %s by [%s]\n", tblock->tm_year+1900,tblock->tm_mon+1,tblock->tm_mday, tblock->tm_hour,tblock->tm_min,tblock->tm_sec,dir,psinfo->sesi50_cname); fprintf(((struct parm *)lParam)->fp,"[%04d-%02d-%02d %02d:%02d:%02d]: Something changed in %s by [%s]\n", tblock->tm_year+1900,tblock->tm_mon+1,tblock->tm_mday, tblock->tm_hour,tblock->tm_min,tblock->tm_sec,dir,psinfo->sesi50_cname); } free(psinfo); FindNextChangeNotification(dwChangeHandle); }}int main(){DWORD thd;FILE *fp1;struct parm my;int count=0;ghDll_SvrApi = LoadLibrary("SVRAPI.DLL"); pSVRNetSessionEnum = (SVR_NETSESSIONENUM)GetProcAddress(ghDll_SvrApi, "NetSessionEnum");printf("Share directory change notify.\n");printf("Copyright NowCan 2000.\n");if((my.fp=fopen("NetMon.log","a"))==NULL) { printf("Open LOG file ERROR!!! Program terminate."); return(0); }if((fp1=fopen("NetMon.ini","r"))==NULL) { printf("Init Error.\n"); printf("Please check fwatch.ini, I give you a sample.\n"); if((fp1=fopen("NetMon.ini","w"))!=NULL) { fprintf(fp1,"d:\\share\nc:\\windows\n"); fclose(fp1); } else { printf("Sorry, I can't give you any sample for some reason.Maybe write protect.\n"); } return(0); }printf("\n");while(fscanf(fp1,"%s\n",my.dirt)!=EOF) { count++; CreateThread(NULL,0,thread,(LPVOID *)&my,0,&thd); Sleep(200); }fclose(fp1);if(count==0) { printf("No directory to watch!"); return(0); }printf("\n\nPress <q> to quit.\n");while(getch()!='q');fclose(my.fp);FreeLibrary(ghDll_SvrApi);return(0);} 再向上提一下!随便问一下: NowCan(能量、激情、雨水、彩虹——雷雨云) 你用的SVRAPI.DLL是在98下的,在2000下没有!怎么办? 使用WNetOpenEnum()和WNetEnumResource()两个函数就可以了 SDI视图分割失败,在CView中添加CFormView类和加入普通CView类有区别吗? wtl 加入 dll 在没vs2005的机子无法运行 用vc2005编译《Windows网络编程技术》附书源码时出错! 请问STL里的set::iterator 有没有"=" 和"!="运算符操作啊 一个关于编译器的问题 请问,如何在向存储过程中传递日期类型? 为啥对CComboBox的初始化工作无效? SDI界面如何使View有滚动条? 不要说我太水 如何共享NT的文件夹并设置访问权限 一台PC共有多少各COM口,为什么好像可以无限制添加? 用cout输出时,如何控制在屏幕上输出的位置?
#pragma hdrstop //如果是VC的话,去掉这三行
#include <condefs.h>
#pragma argsused
#include <windows.h>
#include <stdio.h>
#include <windef.h>
#include <lmcons.h>
#include <lmshare.h>
#include <time.h>
#include <conio.h>
#include <string.h>
USERES("nowcan.res"); //如果是VC的话,去掉这一行
//---------------------------------------------------------------------------typedef DWORD (WINAPI *SVR_NETSESSIONENUM)(const char FAR *pszServer,
short sLevel, char FAR *pbBuffer,
unsigned short cbBuffer,
unsigned short FAR * pcEntriesRead,
unsigned short FAR * pcTotalAvail);struct session_info_50 {
char FAR * sesi50_cname; //remote computer name (connection id in Netware)
char FAR * sesi50_username;
unsigned long sesi50_key; // used to delete session (not used in Netware)
unsigned short sesi50_num_conns;
unsigned short sesi50_num_opens; //not available in Netware
unsigned long sesi50_time;
unsigned long sesi50_idle_time; //not available in Netware
unsigned char sesi50_protocol;
unsigned char pad1;
}; /* session_info_50 */
struct parm
{
char dirt[128];
FILE *fp;
};
SVR_NETSESSIONENUM pSVRNetSessionEnum;
HANDLE ghDll_SvrApi;DWORD WINAPI thread(LPVOID lParam)
{
//DWORD dwWaitStatus;
HANDLE dwChangeHandle;
time_t timer;
struct tm *tblock;
char dir[128];
session_info_50 *psinfo;
WORD ent,t_ent;strcpy(dir,((struct parm *)lParam)->dirt);
dwChangeHandle=FindFirstChangeNotification(dir,
true,FILE_NOTIFY_CHANGE_FILE_NAME|
FILE_NOTIFY_CHANGE_DIR_NAME|
FILE_NOTIFY_CHANGE_ATTRIBUTES|
FILE_NOTIFY_CHANGE_SIZE|
FILE_NOTIFY_CHANGE_LAST_WRITE);
if(dwChangeHandle==INVALID_HANDLE_VALUE)
{
printf("ERROR!!!\n");
return(0);
}
printf("Watch [%s] ready.\n",dir);
while(true)
{
// dwWaitStatus=
WaitForSingleObject(dwChangeHandle,-1);
timer = time(NULL);
psinfo=(struct session_info_50 *) malloc(16384);
pSVRNetSessionEnum(NULL, 50, (char *)psinfo, 16384,&ent,&t_ent);
tblock = localtime(&timer);
if(psinfo->sesi50_num_conns)
{
printf("[%04d-%02d-%02d %02d:%02d:%02d]: Something changed in %s by [%s]\n",
tblock->tm_year+1900,tblock->tm_mon+1,tblock->tm_mday,
tblock->tm_hour,tblock->tm_min,tblock->tm_sec,dir,psinfo->sesi50_cname);
fprintf(((struct parm *)lParam)->fp,"[%04d-%02d-%02d %02d:%02d:%02d]: Something changed in %s by [%s]\n",
tblock->tm_year+1900,tblock->tm_mon+1,tblock->tm_mday,
tblock->tm_hour,tblock->tm_min,tblock->tm_sec,dir,psinfo->sesi50_cname);
}
free(psinfo);
FindNextChangeNotification(dwChangeHandle);
}
}int main()
{
DWORD thd;
FILE *fp1;
struct parm my;
int count=0;
ghDll_SvrApi = LoadLibrary("SVRAPI.DLL");
pSVRNetSessionEnum = (SVR_NETSESSIONENUM)GetProcAddress(ghDll_SvrApi, "NetSessionEnum");printf("Share directory change notify.\n");
printf("Copyright NowCan 2000.\n");
if((my.fp=fopen("NetMon.log","a"))==NULL)
{
printf("Open LOG file ERROR!!! Program terminate.");
return(0);
}
if((fp1=fopen("NetMon.ini","r"))==NULL)
{
printf("Init Error.\n");
printf("Please check fwatch.ini, I give you a sample.\n");
if((fp1=fopen("NetMon.ini","w"))!=NULL)
{
fprintf(fp1,"d:\\share\nc:\\windows\n");
fclose(fp1);
}
else
{
printf("Sorry, I can't give you any sample for some reason.Maybe write protect.\n");
}
return(0);
}
printf("\n");
while(fscanf(fp1,"%s\n",my.dirt)!=EOF)
{
count++;
CreateThread(NULL,0,thread,(LPVOID *)&my,0,&thd);
Sleep(200);
}
fclose(fp1);
if(count==0)
{
printf("No directory to watch!");
return(0);
}
printf("\n\nPress <q> to quit.\n");
while(getch()!='q');
fclose(my.fp);
FreeLibrary(ghDll_SvrApi);
return(0);
}
你用的SVRAPI.DLL是在98下的,在2000下没有!
怎么办?