Might be useful sometimes:
'####################################################################################################################################
' Private Sub btnGetCollections_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetCollections.Click
' Me.checklistCollections.Items.Clear()
' CursorWait(True)
' On Error GoTo err_handler 'Resume Next 'Some error handling
' Dim strserver, strsitecode As String
' Dim colcollections
' Dim objlocator, objsms
' Dim colsitedetails, inssitedetails, inscollection
' strserver = Me.txtSMSServer.Text 'servername
' strsitecode = ""
' objlocator = CreateObject("WbemScripting.SWbemLocator")
' objsms = objlocator.ConnectServer(strserver, "Root/SMS") 'connect to sms
' objsms.Security_.ImpersonationLevel = 3
' 'Me.listLOG.Items.Add("Connecting to Root/SMS on " & strserver)
' colsitedetails = objsms.ExecQuery("select Machine, SiteCode from SMS_ProviderLocation where ProviderForLocalSite=True")
' For Each inssitedetails In colsitedetails
' strsitecode = inssitedetails.SiteCode
' Next
' 'Me.listLOG.Items.Add("Connecting to Root/SMS/site_" & strSiteCode & " on " & strserver)
' objsms = objlocator.ConnectServer(strserver, "root/SMS/site_" + strsitecode)
' 'Me.listLOG.Items.Add("Connected to " & strsitecode)
' colcollections = objsms.ExecQuery("Select CollectionID, Name from SMS_Collection ORDER BY Name")
' For Each inscollection In colcollections
' 'Me.treeCollections.Nodes.Add(inscollection.CollectionID & " - " & inscollection.Name)
' Me.checklistCollections.Items.Add(inscollection.CollectionID & vbTab & inscollection.Name)
' 'DisplaySubCollections(inscollection.CollectionID)
' Next
' Me.listLOG.Items.Add("Successfully connected to SMS Server " & strserver)
' Me.picAddClientsToCollection.Enabled = True
' With My.Settings
' If strserver > 0 Then .SMSServer = strserver
' End With
' CursorWait(False)
' Exit Sub
'err_handler:
' Dim strErrCaption As String
' Dim ErrType As String
' ErrType = MsgBoxStyle.Information
' strErrCaption = "Connection failure"
' If Err.Number = "-2147217394" Then
' MsgBox("There is no SMS Server running on this machine or you are not allowed to query WMI", ErrType, strErrCaption)
' ElseIf Err.Number = "462" Then
' MsgBox("Can't connect to SMS Server '" & strserver & "'" & vbCrLf & vbCrLf & _
' "Please make sure the server is online and you have sufficient rights to query the WMI of the server", ErrType, strErrCaption)
' End If
' CursorWait(False)
' Debug.Print("Line 1: " & Err.Source & vbCrLf & "Line 2: " & Err.Number)
' End Sub
'####################################################################################################################################

Last edited Feb 13, 2008 at 1:00 PM by Spucktier, version 1

Comments

No comments yet.