Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using .NET to create and add new CollectionRule

Status
Not open for further replies.

jspencer15

IS-IT--Management
Mar 15, 2004
4
0
0
US
Hi,
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)
Try
mgmtScope.Connect()
If mgmtScope.IsConnected Then
Dim objCollection As ManagementObject = New ManagementObject(mgmtScope, New ManagementPath("SMS_Collection.CollectionID='A0100019'"), Nothing)
Try
objCollection.Get()
MsgBox("We're connected")
Catch
MsgBox("Couldn't connect")
End Try
Dim objCollRule As ManagementClass = New ManagementClass(mgmtScope, New ManagementPath("SMS_CollectionRuleDirect"), Nothing)
Try
objCollRule.Get()
MsgBox("We're connected...")
Catch
MsgBox("Couldn't connect")
End Try
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
MsgBox(ex.ToString)
End Try
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
 
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")
objCollection.CollectionRules.Add(newCollRule)
objCollection.Save()
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top