Announcement

Collapse
No announcement yet.

Hinzufügen von Rechner in eine SMS-Collection

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hinzufügen von Rechner in eine SMS-Collection

    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 !

  • #2
    Hallo,

    hinter <i>SWbemServices</i> steckt WMI (Windows Management Instrumentation). Die WMI-Objekte des Betriebssystems stellen über Automation-Objekte (siehe <i>Microsoft WMI Scripting V 1.x Library </i>) eine bequemen Aufrufweg für Script-Sprachen zur Verfügung.

    Da WMI seine Dienste über COM-Interfaces zur Verfügung stellt, gibt es für eine .NET-Anwendung in jedem Fall den Weg über COM Interop. Allerdings stellt das .NET-Framework einen einfacheren Weg zur Verfügung, da die Klassen aus dem Namespace <b>System.Management</b> die COM-Objekte von WMI einkapseln.

    WMI unterstützt mit <b>WQL</b> (WMI Query Language) eine Abfragesprache, die stark an SQL angelehnt ist. Das folgende Beispiel demonstriert das Prinzip:
    <pre>
    Imports System.Management
    ...
    Private Function DriveTypeToString(ByVal sDriveTypeNumber As String) As String
    Dim sType As String
    Select Case sDriveTypeNumber
    Case "2"
    sType = "Entfernbares Laufwerk"
    Case "3"
    sType = "Festplatte"
    Case "4"
    sType = "Netzlaufwerk"
    Case "5"
    sType = "CDROM-Laufwerk"
    Case Else
    sType = "(Unbekannt)"
    End Select
    Return sType
    End Function
    <br>
    Private Sub buttonDoWork_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonDoWork.Click
    Dim iCnt As Integer = 0
    Dim sDriveType As String
    listView1.Items.Clear()
    Dim aMAS As New ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")
    Dim aMO As ManagementObject
    For Each aMO In aMAS.Get()
    Dim aLVItem As New ListViewItem(aMO("Name").ToString())
    sDriveType = aMO("DriveType").ToString()
    aLVItem.SubItems.Add(sDriveType + " = " + DriveTypeToString(sDriveType))
    listView1.Items.Add(aLVItem)
    iCnt += 1
    Next
    statusBar1.Text = String.Format("{0} Laufwerke gefunden (VB.NET-Fassung)", iCnt.ToString())
    End Sub
    </pre&gt

    Comment

    Working...
    X