局域网一个共享文件夹,如何知道是哪台机器在访问?

格拉 2009-04-13 03:51:37
系统的我知道,要问的是如何用程序实现,基本上就一个文件监视的作用。
请大家提供思路。谢谢!
...全文
646 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
格拉 2009-04-23
  • 打赏
  • 举报
回复
问题基本上解决,代码贴出来,方便大家

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USER_INFO_502
{
public string ComputerName;
public string Username;
public int Num_FileOpens;
public int S_time;
public int FreeTime;
public int userFlags;
public string CTName;
public string UserTransportName;
}
[DllImport("netapi32.dll", SetLastError = true)]
public static extern int NetSessionEnum(
[In, MarshalAs(UnmanagedType.LPWStr)] string ServerName,
[In, MarshalAs(UnmanagedType.LPWStr)] string UncClientName,
[In, MarshalAs(UnmanagedType.LPWStr)] string UserName,
int Level,
out IntPtr bufptr,
int prefmaxlen,
ref int entriesread,
ref int totalentries,
ref int resume_handle);
private void GetServerMacUserInfo(string ServerName)
{
int EntriesRead=0;
int TotalEntries=0;
int handle = 0;
IntPtr bufPtr;
try
{
richTextBox1.Text = "";
Win32API.NetSessionEnum(ServerName, null, null, 502, out bufPtr,200, ref EntriesRead, ref TotalEntries, ref handle);
//Win32API.NetSessionEnum();
if (EntriesRead > 0)
{
Win32API.USER_INFO_502[] Users = new Win32API.USER_INFO_502[EntriesRead];
IntPtr iter = bufPtr;
for (int i = 0; i < EntriesRead; i++)
{
Users[i] = (Win32API.USER_INFO_502)Marshal.PtrToStructure(iter,typeof(Win32API.USER_INFO_502));
iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(Win32API.USER_INFO_502)));
richTextBox1.Text Users[i].Username +Users[i].ComputerName +Users[i].CTName+Users[i].FreeTime.ToString()+Users[i].Num_FileOpens.ToString()+Users[i].S_time.ToString()+Users[i].userFlags.ToString()+Users[i].UserTransportName+ "\r\n";
}
//Win32API.NetApiBufferFree(bufPtr);
}
}
catch (Exception ee) { MessageBox.Show(ee.Message); }
}

mlhy20060406 2009-04-22
  • 打赏
  • 举报
回复
mark
格拉 2009-04-22
  • 打赏
  • 举报
回复
[DllImport("Netapi32.dll",ExactSpelling = true, CharSet = CharSet.Ansi)]
public extern static long NetSessionEnum()

查了很久,说用这个实现
youqi1984 2009-04-20
  • 打赏
  • 举报
回复
应该用到底层网络原理。
觉得c#实现难度很大
wangzhe1945 2009-04-17
  • 打赏
  • 举报
回复
AD? 哦,多喝AD钙奶,尤其程序员要多喝
boywangliang 2009-04-17
  • 打赏
  • 举报
回复
FlyBee 2009-04-17
  • 打赏
  • 举报
回复
帮顶
格拉 2009-04-17
  • 打赏
  • 举报
回复
0.0
LGP88864237 2009-04-17
  • 打赏
  • 举报
回复
综合上面的说的,调用win32的方法去完成,
调用的代码

[DllImport("Win32.dll")]
public static extern uint aaa();//aaa为方法名
格拉 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 beckfun 的回复:]
引用 15 楼 clxcxx 的回复:
引用 14 楼 pennymay 的回复:
我觉得windows自带就有这个功能, 因为每次关机或者注销的时候, 如果有人连接到我这台电脑,
电脑就会提示有其他用户正在使用,
所以你找找看看是windows的哪个功能,
当然有可能是错的...仅供参考..
会话里有这些信息,只是不知道如何得到

存在会话但并不一定是在访问你的共享文件夹
[/Quote]只得到会话IP和时间就行,文件夹无所谓
beckfun 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 clxcxx 的回复:]
引用 14 楼 pennymay 的回复:
我觉得windows自带就有这个功能, 因为每次关机或者注销的时候, 如果有人连接到我这台电脑,
电脑就会提示有其他用户正在使用,
所以你找找看看是windows的哪个功能,
当然有可能是错的...仅供参考..
会话里有这些信息,只是不知道如何得到
[/Quote]
存在会话但并不一定是在访问你的共享文件夹
格拉 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 pennymay 的回复:]
我觉得windows自带就有这个功能, 因为每次关机或者注销的时候, 如果有人连接到我这台电脑,
电脑就会提示有其他用户正在使用,
所以你找找看看是windows的哪个功能,
当然有可能是错的...仅供参考..
[/Quote]会话里有这些信息,只是不知道如何得到
格拉 2009-04-16
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 cpio 的回复:]

我的电脑,点右键,菜单里面有个管理,在左边的树里面找到共享文件夹,下面有打开文件以及会话列表
[/Quote]这个知道,谢谢了
cpio 2009-04-16
  • 打赏
  • 举报
回复

我的电脑,点右键,菜单里面有个管理,在左边的树里面找到共享文件夹,下面有打开文件以及会话列表
pennymay 2009-04-15
  • 打赏
  • 举报
回复
我觉得windows自带就有这个功能, 因为每次关机或者注销的时候, 如果有人连接到我这台电脑,
电脑就会提示有其他用户正在使用,
所以你找找看看是windows的哪个功能,
当然有可能是错的...仅供参考..
格拉 2009-04-15
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 beckfun 的回复:]
其实也就是防火墙的原理!
[/Quote]谢谢帮助!大家继续
beckfun 2009-04-15
  • 打赏
  • 举报
回复
其实也就是防火墙的原理!
beckfun 2009-04-15
  • 打赏
  • 举报
回复
不知道怎么分析数据包,所以....
beckfun 2009-04-15
  • 打赏
  • 举报
回复
拦截数据包!分析数据包!数据包中就藏着你和访问着的IP地址!
深海之蓝 2009-04-15
  • 打赏
  • 举报
回复
干脆建个ftp得了
用servu
谁访问的都知道
加载更多回复(8)

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧