Hi!
I'm trying to erase SMS_Collection Rules using VB.NET 2003...
I did that with WbemScripting, but now I need to do it with
System.Manageme nt...
My problem is that with System.Manageme nt I cannot get directly the item
without enumerating a bunch of them (as I know)...
How can I do this...
_______________ _______________ _______________ __________
Collection = Server.Get("SMS _Collection='" & CollectionID & "'")
_______________ _______________ _______________ __________
With System.Manageme nt
The only way I know is doing a For Each of what is being returned from
something like...
_______________ _______________ _______________ __________
Private Function GetObjects(ByVa l Query As String) As
ManagementObjec tCollection
Dim SMSObject As ManagementObjec t
Dim SMSSearcher As ManagementObjec tSearcher
Dim SMSQuery As ManagementQuery
Try
SMSQuery = New WqlObjectQuery( Query)
SMSSearcher = New ManagementObjec tSearcher(SMSSc ope, SMSQuery)
Return SMSSearcher.Get
Catch ex As Exception
Return Nothing
End Try
End Function
_______________ _______________ _______________ __________
So here is my code for WbemScripting.. .
_______________ _______________ _______________ __________
Private Locator As SWbemLocator
Private Server As SWbemServices
Public SMSMainSite As String
Public Function Connect(ByVal SMSServer As String) As Boolean
Try
Locator = New SWbemLocator
Server = Locator.Connect Server(SMSServe r, "root\sms")
Catch ex As Exception
Return False
End Try
Dim Sites As SWbemObjectSet
Dim Site As SWbemObject
Try
Sites = Server.ExecQuer y("Select SiteCode From
SMS_ProviderLoc ation Where ProviderForLoca lSite=True")
For Each Site In Sites
SMSMainSite = Site.SiteCode
Next
Server = Locator.Connect Server(SMSServe r, "root\sms\site_ " &
SMSMainSite)
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function DeleteCollectio nRules(ByVal CollectionID As String) As Boolean
Dim Collection As SWbemObject
Dim Prop As SWbemProperty
Dim Rules() As Object
Dim Method As SWbemMethod
Dim Parameters As SWbemObject
Try
Collection = Server.Get("SMS _Collection='" & CollectionID & "'")
Prop = Collection.Prop erties_.Item("C ollectionRules" )
If Not Prop.Value Is System.DBNull.V alue Then Rules = Prop.Value
If Not IsNothing(Rules ) Then
Method = Collection.Meth ods_.Item("Dele teMembershipRul es")
Parameters = Method.InParame ters.SpawnInsta nce_
Parameters.Prop erties_.Item("c ollectionRules" ).Value = Rules
Collection.Exec Method_("Delete MembershipRules ", Parameters)
End If
Catch ex As Exception
Return False
End Try
Return True
End Function
_______________ _______________ _______________ __________
Thanks!
ShrimpyOne
I'm trying to erase SMS_Collection Rules using VB.NET 2003...
I did that with WbemScripting, but now I need to do it with
System.Manageme nt...
My problem is that with System.Manageme nt I cannot get directly the item
without enumerating a bunch of them (as I know)...
How can I do this...
_______________ _______________ _______________ __________
Collection = Server.Get("SMS _Collection='" & CollectionID & "'")
_______________ _______________ _______________ __________
With System.Manageme nt
The only way I know is doing a For Each of what is being returned from
something like...
_______________ _______________ _______________ __________
Private Function GetObjects(ByVa l Query As String) As
ManagementObjec tCollection
Dim SMSObject As ManagementObjec t
Dim SMSSearcher As ManagementObjec tSearcher
Dim SMSQuery As ManagementQuery
Try
SMSQuery = New WqlObjectQuery( Query)
SMSSearcher = New ManagementObjec tSearcher(SMSSc ope, SMSQuery)
Return SMSSearcher.Get
Catch ex As Exception
Return Nothing
End Try
End Function
_______________ _______________ _______________ __________
So here is my code for WbemScripting.. .
_______________ _______________ _______________ __________
Private Locator As SWbemLocator
Private Server As SWbemServices
Public SMSMainSite As String
Public Function Connect(ByVal SMSServer As String) As Boolean
Try
Locator = New SWbemLocator
Server = Locator.Connect Server(SMSServe r, "root\sms")
Catch ex As Exception
Return False
End Try
Dim Sites As SWbemObjectSet
Dim Site As SWbemObject
Try
Sites = Server.ExecQuer y("Select SiteCode From
SMS_ProviderLoc ation Where ProviderForLoca lSite=True")
For Each Site In Sites
SMSMainSite = Site.SiteCode
Next
Server = Locator.Connect Server(SMSServe r, "root\sms\site_ " &
SMSMainSite)
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function DeleteCollectio nRules(ByVal CollectionID As String) As Boolean
Dim Collection As SWbemObject
Dim Prop As SWbemProperty
Dim Rules() As Object
Dim Method As SWbemMethod
Dim Parameters As SWbemObject
Try
Collection = Server.Get("SMS _Collection='" & CollectionID & "'")
Prop = Collection.Prop erties_.Item("C ollectionRules" )
If Not Prop.Value Is System.DBNull.V alue Then Rules = Prop.Value
If Not IsNothing(Rules ) Then
Method = Collection.Meth ods_.Item("Dele teMembershipRul es")
Parameters = Method.InParame ters.SpawnInsta nce_
Parameters.Prop erties_.Item("c ollectionRules" ).Value = Rules
Collection.Exec Method_("Delete MembershipRules ", Parameters)
End If
Catch ex As Exception
Return False
End Try
Return True
End Function
_______________ _______________ _______________ __________
Thanks!
ShrimpyOne
Comment