C# 如何在 Windows 共享中找到与资源的连接并删除其中一些
我想通过在控制台中输入“net file”来获得结果。
我试图找到一种方法来通过 WMI Win32 类获取我需要的信息,但我觉得我无法列出正在使用的实际资源。我最接近的是使用 Win32_ServerSession,其中我可以列出具有连接的共享,但不能列出资源本身。
我是否遗漏了什么,如何获得结果?
编辑:
我无法使用“net file”,因为如果路径很长,字符串将被截断。
示例:
D:\shares\files\photo\image.jpg 将列为 D:\share\...\image.jpg
相同的文件列表,但具有完整路径,可以在计算机管理 -> 下找到系统工具->共享文件夹->打开文件
I want to get the result I am able to get by typing "net file" in console.
I have tried to find a way to get the information I need through WMI Win32 Classes, but it seams to me that I can't list the actual resources in use. The closest I have come is to use Win32_ServerSession, where i can list the shares that has connections, but not the resource itself.
Is there something I have missed, how can I get my result?
Edit:
I can't use "net file", because the strings are being truncated if the path is long.
Example:
D:\shares\files\photo\image.jpg will be listed as D:\share\...\image.jpg
The same list of files, but with full path, can be found under Computer Management -> System Tools -> Shared Folders -> Open Files
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢曼弗雷德,我成功了。如果您遇到同样的问题,从这里获取代码。
Thanks to Manfred, i got this working. If you got the same problem, Get the code from here.
是的,这只是 MS 在 WMI 中提供的基本功能的又一个缺失……:-(
就像许多其他令人兴奋的事情一样,例如提供商或 WQL 2.0 [仅限 SMS!!!] - BUH!
只需使用 Net API 即可完成此操作。我有一个样本,但太长,无法发布
它在这里[我不会为此接受任何保证;-)]。
如果您有兴趣,请直接联系我。
br++马布拉
That's right, just another lack of basic features MS offers within WMI ... :-(
like many other exciting things like providers or WQL 2.0 [only SMS!!!!] - BUH!
Just use the Net API to do this. I have a sample, but it is too long to post
it here [and I would not take any guarentee for it ;-) ].
If you are interested, contact me directly.
br++mabra