如何使用 C# 获取计算机的工作组名称?
我读过有关通过环境类获取它的信息,但找不到它。
谢谢你们。
I've read about getting it with the Environment class, but can't find it.
Thanks guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一种基于 Jono 响应的方法,但更短:
A way based on the Jono response, but shorter:
我使用此处建议的 WMI 选项尝试了此操作,但结果在我的计算机(以及我办公室的其他几台计算机)上速度非常慢(有时超过 5 秒)。最终对我有用的是使用 API 调用“NetGetJoinInformation”(PInvoke.net)。 API 调用对我来说返回得非常快,并且完全满足了我的需要。
I tried this using the WMI options suggested here, but it turned out to be excruciatingly slow (sometimes over 5 seconds) on my machine (and several others in my office). What ended up working for me was using the API call "NetGetJoinInformation" (PInvoke.net). The API call returns very quickly for me and does exactly what I need.
您可以使用 WMI 来完成此操作;添加对 System.Management.dll 的引用和 System.Management 命名空间的 using 语句,然后调用以下代码:
You can do this with WMI; add a reference to System.Management.dll and a using statement for System.Management namespace, then call the following code:
请参阅此处查看示例。您将必须使用 P/Invoke。
Look here for an example. You will have to use P/Invoke.