Hi All,
I'm trying to write a VB .NET 2003 application to add and remove items from
an SMS 2003 collection. I've found some code that does this using
WbemScripting. However, I'd like to do this via Systems.Managem ent.
The 'basic/partial' WbemScripting code that I would like to convert is
listed below:
WbemServices = loc.ConnectServ er("SMS", "root\sms\site_ SMS")
instCollection =
WbemServices.Ge t("SMS_Collecti on.CollectionID =""SMS001B4" "")
instDirectRule =
WbemServices.Ge t("SMS_Collecti onRuleDirect"). SpawnInstance_
instDirectRule. ResourceClassNa me = "SMS_R_Syst em"
instDirectRule. ResourceClassNa me = "SMS_R_User "
instDirectRule. ResourceID = strResourceID
instDirectRule. RuleName = strRuleName
instCollection. AddMembershipRu le(instDirectRu le)
I can read from the collections just fine using systems.managem ent.
However, I'm not sure how to create a direct membership rule, or set the
parameters for ResourceClassNa me, ResourceID, etc.
My basic code:
Private Sub ConnectToWMI()
Try
myConnectionOpt ions = New ConnectionOptio ns
With myConnectionOpt ions
.Impersonation =
System.Manageme nt.Impersonatio nLevel.Imperson ate
.Authentication = System.Manageme nt.Authenticati onLevel.Packet
End With
myManagementSco pe = New
ManagementScope ("\\SMS\root\sm s\site_SMS", myConnectionOpt ions)
myManagementSco pe.Connect()
myConnectionOpt ions = Nothing
Catch ex As Exception
MsgBox("Error")
myConnectionOpt ions = Nothing
End Try
End Sub
Private Sub AddToCollection ()
Dim strComputerName as String = "TestComput er"
Dim objQuery As ObjectQuery
Dim instance As ManagementObjec t
Dim collectionClass As New ManagementClass (myManagementSc ope, New
ManagementPath( "SMS_Collection .CollectionID=" "SMS001B4"" "), Nothing)
Dim directruleClass As New ManagementClass (myManagementSc ope, New
ManagementPath( "SMS_Collection RuleDirect"), Nothing)
.... <This is where I start getting stuck. How do I create an instance of
the direct rule, set the 'ResourceClassN ame' properties, and invoke the
method to 'AddMembershipR ule'?>
End Sub
Any help would be much appreciated.
Thanks!
--
Pete
I'm trying to write a VB .NET 2003 application to add and remove items from
an SMS 2003 collection. I've found some code that does this using
WbemScripting. However, I'd like to do this via Systems.Managem ent.
The 'basic/partial' WbemScripting code that I would like to convert is
listed below:
WbemServices = loc.ConnectServ er("SMS", "root\sms\site_ SMS")
instCollection =
WbemServices.Ge t("SMS_Collecti on.CollectionID =""SMS001B4" "")
instDirectRule =
WbemServices.Ge t("SMS_Collecti onRuleDirect"). SpawnInstance_
instDirectRule. ResourceClassNa me = "SMS_R_Syst em"
instDirectRule. ResourceClassNa me = "SMS_R_User "
instDirectRule. ResourceID = strResourceID
instDirectRule. RuleName = strRuleName
instCollection. AddMembershipRu le(instDirectRu le)
I can read from the collections just fine using systems.managem ent.
However, I'm not sure how to create a direct membership rule, or set the
parameters for ResourceClassNa me, ResourceID, etc.
My basic code:
Private Sub ConnectToWMI()
Try
myConnectionOpt ions = New ConnectionOptio ns
With myConnectionOpt ions
.Impersonation =
System.Manageme nt.Impersonatio nLevel.Imperson ate
.Authentication = System.Manageme nt.Authenticati onLevel.Packet
End With
myManagementSco pe = New
ManagementScope ("\\SMS\root\sm s\site_SMS", myConnectionOpt ions)
myManagementSco pe.Connect()
myConnectionOpt ions = Nothing
Catch ex As Exception
MsgBox("Error")
myConnectionOpt ions = Nothing
End Try
End Sub
Private Sub AddToCollection ()
Dim strComputerName as String = "TestComput er"
Dim objQuery As ObjectQuery
Dim instance As ManagementObjec t
Dim collectionClass As New ManagementClass (myManagementSc ope, New
ManagementPath( "SMS_Collection .CollectionID=" "SMS001B4"" "), Nothing)
Dim directruleClass As New ManagementClass (myManagementSc ope, New
ManagementPath( "SMS_Collection RuleDirect"), Nothing)
.... <This is where I start getting stuck. How do I create an instance of
the direct rule, set the 'ResourceClassN ame' properties, and invoke the
method to 'AddMembershipR ule'?>
End Sub
Any help would be much appreciated.
Thanks!
--
Pete