简体   繁体   English

通过C#从Winapi的“ net use”中获取状态列

[英]get status column from “net use” with winapi via C#

When issuing the "net use" command in Windows there is a "Status" column. 在Windows中发出“ net use”命令时,会有一个“状态”列。 Is it possible to get that via any of the methods found in the mpr.dll? 是否有可能通过mpr.dll中找到的任何方法来获取?

I'm currently using WNetOpenEnum and then using WNetEnumResource to iterate though the drives that are mapped. 我当前正在使用WNetOpenEnum,然后使用WNetEnumResource来迭代已映射的驱动器。 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. 我以为NetResource结构中的一个字段会指定状态,但是当我运行“ net use”并有两个驱动器时,其中一个的状态为“ OK”,而其中的一个状态为“ Unavailable”,则这些字段都是相同。

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. 有时,当所有其他方法都失败时,我会走“ hacky”路线来完成所需的工作。

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. 在这种情况下,我可能会尝试将net use的输出管道传输到.txt文件(可能在系统的Temp文件夹中),将其读入并解析为我需要的内容,然后将其从系统中删除,仅用于保持清洁。

ie net use > C:\\Temp\\netuse.txt net use > C:\\Temp\\netuse.txt

You might be able to do this with the win32_share class since it supports IPC and status. 您可以使用win32_share类执行此操作,因为它支持IPC和状态。 try checking out http://www.mvps.org/emorcillo/en/code/grl/share.shtml 尝试查看http://www.mvps.org/emorcillo/en/code/grl/share.shtml

Yes - its vb.net, but may give you what you need here 是的-它的vb.net,但可以在这里给您您所需要的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM