Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem using .NET to create and add new CollectionRule

Problem using .NET to create and add new CollectionRule

Problem using .NET to create and add new CollectionRule

   I'm building an asp.net website to administer SMS. There is a relatively simple function I've been using for quite some time in Visual Basic to add a computer to a collection. However when I take the code verbatim and add it to a .NET website I get inconsistent results. Sometimes the computer gets added, sometimes it doesn't I never see any errors or anything that would indicate there was a failure. What's even stranger is that sometimes it will appear as though the computer was added (if I click on the collection in the MMC I'll see the computer name listed in the right panel) yet when I right-click the collection, choose Properties, then choose Membership Rules, the computer isn't there! The VB code (which works consistently) is listed below. The only changes I've made in my asp.net page is replacing all occurences of msgbox with response.write. Any help or ideas would be greatly appreciated.

'This is the collection ID I want to add to: "A0100019"
'Computer to add to collection: "MyIBM"
'ResourceID of "MyIBM": 15853

Dim conOptions As New System.Management.ConnectionOptions
Dim mgmtScope As ManagementScope = New ManagementScope("\\SMSxx\root\sms\site_x01", conOptions)
   If mgmtScope.IsConnected Then
      Dim objCollection As ManagementObject = New ManagementObject(mgmtScope, New ManagementPath("SMS_Collection.CollectionID='A0100019'"), Nothing)
         MsgBox("We're connected")
         MsgBox("Couldn't connect")
      End Try
      Dim objCollRule As ManagementClass = New ManagementClass(mgmtScope, New ManagementPath("SMS_CollectionRuleDirect"), Nothing)
         MsgBox("We're connected...")
         MsgBox("Couldn't connect")
      End Try
         Dim objNewRule As ManagementObject = objCollRule.CreateInstance()
         Dim str1 As String = "SMS_R_System"
         Dim str2 As String = "15853"
         Dim str3 As String = "MyIBM"
         objNewRule.SetPropertyValue("ResourceClassName", str1)
         objNewRule.SetPropertyValue("ResourceID", str2)
         objNewRule.SetPropertyValue("RuleName", str3)
         Dim objArgs() As Object = {objNewRule}
         objCollection.InvokeMethod("AddMemberShipRule", objArgs)
         MsgBox("Should be done...")
      Catch ex As Exception
      End Try
   End If
Catch ex As Exception
End Try

RE: Problem using .NET to create and add new CollectionRule

Check out the managed API (.net DLL) in the SMS 2003 SDK

RE: Problem using .NET to create and add new CollectionRule

Thanks. I've tried using the api but my background is more scripter than programmer. I'm slowly coming up to speed on ASP.NET and I've got the dll added as a reference. It's actually a lot less code (see below) to do the same function:
        Dim oProvider As New SMSProvider("SMS0X", "myUserName", "myPassword")
        Dim objCollection As Microsoft.SystemsManagementServer.Automation.SMSCollection
        objCollection = oProvider.Collections.Get("A0100019")
        Dim newCollRule As New Microsoft.SystemsManagementServer.Automation.SMSCollectionRuleDirect("SMS_R_System", "15853", "myIBM")
Unfortunately I'm experiencing the same anomalies using this code. More testing shows that it may be an integrated authentication issue with IIS.
However, I would really like more information on how to use the API. Does anyone have any good references for this?

Thanks for all your help!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close