Simple Question about WMI in C#

  • Thread starter Thread starter David zha0
  • Start date Start date
D

David zha0

Hi,

I just want to write a small program to do some job on the remote system
with WMI, and my question is how can I deal with the WMI connection? To
connect the remote host once we need or just keep the connection alive?

I think maybe I can use a singleton pattern here, but I'm not sure what
the singleton should return, a ConnectionOptions or a ManagementScope?
 
David,

I don't see what having a singleton here does for you. Perhaps if you
wanted to keep an open/persistant connection, then I can understand. In
that case, I would probably go with a ManagementScope instance. If you
return a ConnectionOptions instance, you will probably keep creating the
ManagementScope instance for your operations over and over again, and that's
extra code you don't have to write.
 
Nicholas:

Thanks a lot for your reply, I meant to persist the connection during almost
the
whole lifetime of the program and, the ConnectionOptions won't be changed.

I think it is clear that I should keep an ManagementScope object...
Sorry for the stupid question :)

Thanks again.



Nicholas Paldino said:
David,

I don't see what having a singleton here does for you. Perhaps if you
wanted to keep an open/persistant connection, then I can understand. In
that case, I would probably go with a ManagementScope instance. If you
return a ConnectionOptions instance, you will probably keep creating the
ManagementScope instance for your operations over and over again, and
that's extra code you don't have to write.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


David zha0 said:
Hi,

I just want to write a small program to do some job on the remote
system
with WMI, and my question is how can I deal with the WMI connection? To
connect the remote host once we need or just keep the connection alive?

I think maybe I can use a singleton pattern here, but I'm not sure
what
the singleton should return, a ConnectionOptions or a ManagementScope?
 
Nicholas:

Thanks a lot for your reply, I meant to persist the connection during almost
the
whole lifetime of the program and, the ConnectionOptions won't be changed.

I think it is clear that I should keep an ManagementScope object...
Sorry for the stupid question :)

Thanks again.



Nicholas Paldino said:
David,

I don't see what having a singleton here does for you. Perhaps if you
wanted to keep an open/persistant connection, then I can understand. In
that case, I would probably go with a ManagementScope instance. If you
return a ConnectionOptions instance, you will probably keep creating the
ManagementScope instance for your operations over and over again, and
that's extra code you don't have to write.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


David zha0 said:
Hi,

I just want to write a small program to do some job on the remote
system
with WMI, and my question is how can I deal with the WMI connection? To
connect the remote host once we need or just keep the connection alive?

I think maybe I can use a singleton pattern here, but I'm not sure
what
the singleton should return, a ConnectionOptions or a ManagementScope?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top