从“net use”获取状态列通过 C# 使用 winapi
在 Windows 中发出“net use”命令时,会出现一个“状态”列。是否可以通过 mpr.dll 中找到的任何方法来获取它?
我当前正在使用 WNetOpenEnum,然后使用 WNetEnumResource 来迭代映射的驱动器。我可以获得除状态之外的所有列。
我认为 NetResource 结构中的字段之一将指定状态,但是当我运行“net use”并有两个驱动器时,其中一个的状态为“正常”,其中一个的状态为“不可用”,则这些字段全部为相同。
When issuing the "net use" command in Windows there is a "Status" column. Is it possible to get that via any of the methods found in the mpr.dll?
I'm currently using WNetOpenEnum and then using WNetEnumResource to iterate though the drives that are mapped. I can get all of the columns except status.
I thought that one of the fields in the NetResource struct would specify the status, but when I run "net use" and have two drives, one of which has Status of "OK" and one of which is "Unavailable" the fields are all the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 win32_share 类来执行此操作,因为它支持 IPC 和状态。
尝试签出
http://www.mvps.org/emorcillo/en/code/grl /share.shtml
是的 - 它是 vb.net,但可以在这里给你你需要的东西
You might be able to do this with the win32_share class since it supports IPC and status.
try checking out
http://www.mvps.org/emorcillo/en/code/grl/share.shtml
Yes - its vb.net, but may give you what you need here
我知道这是一篇非常古老的帖子,但我在一些搜索过程中偶然发现了它,并认为无论如何我都会提出一个想法。有时,当所有其他方法都失败时,我会采取“黑客”路线来完成我需要完成的事情。
在这种情况下,我可能会尝试将
net use
的输出通过管道传输到 .txt 文件(可能在系统的 Temp 文件夹中),将其读取并解析为我需要的内容,然后删除它来自系统,只是为了保持干净。即
网络使用> C:\Temp\netuse.txt
I know this is a really old post, but I stumbled upon it during some searches, and thought I'd chime in with an idea anyway. Sometimes when all else fails, I go a 'hacky' route to get what I need done.
In this case, I might try just piping the output of
net use
to a .txt file, (probably in the System's Temp folder), reading it in, and parsing it for what I need, then deleting it from the system, just to keep things clean.i.e.
net use > C:\Temp\netuse.txt