Hallo zusammen !
Es gibt da ein Problem: Ich möchte auf einem SMS Server 2003 einer bestehenden Collection ein Rechner zuteilen - und das mit VB.NET
Für die Aktion gibt es auch schon "fertigen" Visual Basic 6 Code. Leider bin ich nicht in der Lage, diesen Code nach VB.Net zu konvertieren. Mein Hauptproblem liegt dabei in folgendem Abschnitt des codes (Hauptaugenmerk auf SWBEM...:
--------------------
Private Sub cmdAddToCollection_Click()
Dim wbemServices As SWbemServices
Dim wbemLocator As New SWbemLocator
Dim Query As String
Dim QueryResults As SWbemObjectSet
Dim QueryResult As SWbemObject
Dim InstCollection As SWbemObject
Dim InstDirectRule As SWbemObject
Dim InstCollectionID, InstCollectionName As String
Dim RuleSet() As Variant
Dim Rule As Variant
Dim SMSResourceID As String
Set wbemServices = wbemLocator.ConnectServer("S59BMS11", "root\sms\site_SIF")
'Query Advertisement with the PackageID
Query = "select * from SMS_Advertisement where PackageID = """ & RefreshSMSID & """ and AdvertisementName Like 'DS%'"
Set QueryResults = wbemServices.ExecQuery(Query)
For Each QueryResult In QueryResults
InstCollectionID = QueryResult.CollectionID
Next QueryResult
'Exit Sub if there is no DS Collection
If InstCollectionID = "" Then
MsgBox ("Es existiert keine DS Collection für dieses SMS Paket ! ")
Exit Sub
End If
'Get the SMSResourceID of the client
Query = "select SMS_R_System.ResourceID from SMS_R_System where SMS_R_System.Name = """ & ClientNameWithoutDNS & """"
Set QueryResults = wbemServices.ExecQuery(Query)
For Each QueryResult In QueryResults
SMSResourceID = QueryResult.ResourceID
Debug.Print SMSResourceID
Next QueryResult
'Get InstCollection
Set InstCollection = wbemServices.Get("SMS_Collection.CollectionID=""" & InstCollectionID & """")
InstCollectionName = InstCollection.Name
'Get the array of embedded SMS_CollectionRule objects.
If IsNull(InstCollection.CollectionRules) Then
Else
RuleSet = InstCollection.CollectionRules
For Each Rule In RuleSet
If UCase(Trim(Rule.RuleName)) = ClientNameWithoutDNS Then
MsgBox ("Client ist schon ein Mitglied der Collection")
Exit Sub
End If
Next
End If
If Not (SMSResourceID = "") Then
'Create the direct rule.
Set InstDirectRule = wbemServices.Get("SMS_CollectionRuleDirect").Spawn Instance_
InstDirectRule.ResourceClassName = "SMS_R_System"
InstDirectRule.ResourceID = SMSResourceID
InstDirectRule.RuleName = ClientNameWithoutDNS
'Add the direct rule to the collection.
InstCollection.AddMembershipRule InstDirectRule
MsgText = "Rechner in die Collection '" + InstCollectionName + "' aufgenommen."
MsgBox (MsgText)
Else
MsgBox ("Sorry, dieser Rechner ist im SMS nicht inventarisiert !")
End If
End Sub
----------------
Wer kann (und ist bereit :-) ) mir da helfen ?
Danke im Voraus !
Es gibt da ein Problem: Ich möchte auf einem SMS Server 2003 einer bestehenden Collection ein Rechner zuteilen - und das mit VB.NET
Für die Aktion gibt es auch schon "fertigen" Visual Basic 6 Code. Leider bin ich nicht in der Lage, diesen Code nach VB.Net zu konvertieren. Mein Hauptproblem liegt dabei in folgendem Abschnitt des codes (Hauptaugenmerk auf SWBEM...:
--------------------
Private Sub cmdAddToCollection_Click()
Dim wbemServices As SWbemServices
Dim wbemLocator As New SWbemLocator
Dim Query As String
Dim QueryResults As SWbemObjectSet
Dim QueryResult As SWbemObject
Dim InstCollection As SWbemObject
Dim InstDirectRule As SWbemObject
Dim InstCollectionID, InstCollectionName As String
Dim RuleSet() As Variant
Dim Rule As Variant
Dim SMSResourceID As String
Set wbemServices = wbemLocator.ConnectServer("S59BMS11", "root\sms\site_SIF")
'Query Advertisement with the PackageID
Query = "select * from SMS_Advertisement where PackageID = """ & RefreshSMSID & """ and AdvertisementName Like 'DS%'"
Set QueryResults = wbemServices.ExecQuery(Query)
For Each QueryResult In QueryResults
InstCollectionID = QueryResult.CollectionID
Next QueryResult
'Exit Sub if there is no DS Collection
If InstCollectionID = "" Then
MsgBox ("Es existiert keine DS Collection für dieses SMS Paket ! ")
Exit Sub
End If
'Get the SMSResourceID of the client
Query = "select SMS_R_System.ResourceID from SMS_R_System where SMS_R_System.Name = """ & ClientNameWithoutDNS & """"
Set QueryResults = wbemServices.ExecQuery(Query)
For Each QueryResult In QueryResults
SMSResourceID = QueryResult.ResourceID
Debug.Print SMSResourceID
Next QueryResult
'Get InstCollection
Set InstCollection = wbemServices.Get("SMS_Collection.CollectionID=""" & InstCollectionID & """")
InstCollectionName = InstCollection.Name
'Get the array of embedded SMS_CollectionRule objects.
If IsNull(InstCollection.CollectionRules) Then
Else
RuleSet = InstCollection.CollectionRules
For Each Rule In RuleSet
If UCase(Trim(Rule.RuleName)) = ClientNameWithoutDNS Then
MsgBox ("Client ist schon ein Mitglied der Collection")
Exit Sub
End If
Next
End If
If Not (SMSResourceID = "") Then
'Create the direct rule.
Set InstDirectRule = wbemServices.Get("SMS_CollectionRuleDirect").Spawn Instance_
InstDirectRule.ResourceClassName = "SMS_R_System"
InstDirectRule.ResourceID = SMSResourceID
InstDirectRule.RuleName = ClientNameWithoutDNS
'Add the direct rule to the collection.
InstCollection.AddMembershipRule InstDirectRule
MsgText = "Rechner in die Collection '" + InstCollectionName + "' aufgenommen."
MsgBox (MsgText)
Else
MsgBox ("Sorry, dieser Rechner ist im SMS nicht inventarisiert !")
End If
End Sub
----------------
Wer kann (und ist bereit :-) ) mir da helfen ?
Danke im Voraus !
Comment