简体   繁体   English

管理远程WMI连接

[英]Managing remote WMI connections

I code in mostly VBScript and have a question regarding a C# ASP.NET application that I'm writing that will do remote WMI queries for information (specifically to Systems Center Configuration Manager (SCCM)). 我主要使用VBScript进行编码,并且对正在编写的C#ASP.NET应用程序有疑问,该应用程序将对信息进行远程WMI查询(特别是Systems Center Configuration Manager(SCCM))。 The examples shown in the SDK (http://msdn.microsoft.com/en-us/library/cc145284.aspx) for Config Mgr 2007 show a connection being created to the remote server and calling snipplets (methods) in another class. Config Mgr 2007的SDK(http://msdn.microsoft.com/zh-cn/library/cc145284.aspx)中显示的示例显示了正在创建到远程服务器的连接并在另一个类中调用代码段(方法)。 However, in this application I would be making numerous calls to the remote server and I'm curious to know how C# manages and closes this connection? 但是,在这个应用程序中,我将对远程服务器进行无数次调用,并且我很想知道C#如何管理和关闭此连接? If I called multiple 'snipplets', does it maintain a single connection to the server or would each 'snipplet' called create a new connection to the server. 如果我调用了多个“代码段”,它是保持与服务器的单个连接,还是每个调用的“代码段”都将创建与服务器的新连接。 My concern is having 300 connections to the server because I don't see an .Close or any cleanup of the connection. 我关心的是与服务器建立300个连接,因为没有看到.Close或连接的任何清理。 I would just like to ensure my class is built properly and not making a multitude of connections to the remote server before I continue building my application. 我只想确保我的类正确构建,并且在继续构建应用程序之前不与远程服务器建立大量连接。 Thanks for any input. 感谢您的任何投入。

Where do you see these 300 connections?? 您在哪里看到这300个连接?

Net management Classes are finally based on the WMI COM interfaces and classes;Even there, you'll missing a "Close". 网络管理类最终基于WMI COM接口和类;即使在这里,您也会缺少“关闭”字样。 From what I think [ :-) ] and my experience, the connection will disappear automatically, if your objects are all properly disposed. 根据我的想法[:-)和我的经验,如果正确放置了所有对象,则连接将自动消失。

What I recommend, is, create a ManagementScope first and use it all the time in your other methods and queries. 我建议首先创建一个ManagementScope,然后在其他方法和查询中始终使用它。 Finally, get rid of it. 最后,摆脱它。

You should show one of your methods, to become more specific! 您应该展示一种方法,以使其更加具体!

br++mabra br ++ mabra

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

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