|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
System.Management VS WbemScriptingI'm trying to erase SMS_Collection Rules using VB.NET 2003... I did that with WbemScripting, but now I need to do it with System.Management... My problem is that with System.Management I cannot get directly the item without enumerating a bunch of them (as I know)... How can I do this... _______________________________________________________ Collection = Server.Get("SMS_Collection='" & CollectionID & "'") _______________________________________________________ With System.Management The only way I know is doing a For Each of what is being returned from something like... _______________________________________________________ Private Function GetObjects(ByVal Query As String) As ManagementObjectCollection Dim SMSObject As ManagementObject Dim SMSSearcher As ManagementObjectSearcher Dim SMSQuery As ManagementQuery Try SMSQuery = New WqlObjectQuery(Query) SMSSearcher = New ManagementObjectSearcher(SMSScope, SMSQuery) Return SMSSearcher.Get Catch ex As Exception Return Nothing End Try End Function _______________________________________________________ So here is my code for WbemScripting... _______________________________________________________ Private Locator As SWbemLocator Private Server As SWbemServices Public SMSMainSite As String Public Function Connect(ByVal SMSServer As String) As Boolean Try Locator = New SWbemLocator Server = Locator.ConnectServer(SMSServer, "root\sms") Catch ex As Exception Return False End Try Dim Sites As SWbemObjectSet Dim Site As SWbemObject Try Sites = Server.ExecQuery("Select SiteCode From SMS_ProviderLocation Where ProviderForLocalSite=True") For Each Site In Sites SMSMainSite = Site.SiteCode Next Server = Locator.ConnectServer(SMSServer, "root\sms\site_" & SMSMainSite) Catch ex As Exception Return False End Try Return True End Function Public Function DeleteCollectionRules(ByVal CollectionID As String) As Boolean Dim Collection As SWbemObject Dim Prop As SWbemProperty Dim Rules() As Object Dim Method As SWbemMethod Dim Parameters As SWbemObject Try Collection = Server.Get("SMS_Collection='" & CollectionID & "'") Prop = Collection.Properties_.Item("CollectionRules") If Not Prop.Value Is System.DBNull.Value Then Rules = Prop.Value If Not IsNothing(Rules) Then Method = Collection.Methods_.Item("DeleteMembershipRules") Parameters = Method.InParameters.SpawnInstance_ Parameters.Properties_.Item("collectionRules").Value = Rules Collection.ExecMethod_("DeleteMembershipRules", Parameters) End If Catch ex As Exception Return False End Try Return True End Function _______________________________________________________ Thanks! ShrimpyOne Hi ShrimpBoy.
Do you want to get which of 'object' and 'collection' ? o Get() returns 'object' itself. o ExecQuery returns 'collection' as collection of object. Show quoteHide quote "ShrimpBoy" wrote: > Hi! > > I'm trying to erase SMS_Collection Rules using VB.NET 2003... > > I did that with WbemScripting, but now I need to do it with > System.Management... > > My problem is that with System.Management I cannot get directly the item > without enumerating a bunch of them (as I know)... > > How can I do this... > > _______________________________________________________ > > Collection = Server.Get("SMS_Collection='" & CollectionID & "'") > _______________________________________________________ > > With System.Management > > The only way I know is doing a For Each of what is being returned from > something like... > _______________________________________________________ > > Private Function GetObjects(ByVal Query As String) As > ManagementObjectCollection > > Dim SMSObject As ManagementObject > Dim SMSSearcher As ManagementObjectSearcher > Dim SMSQuery As ManagementQuery > > Try > > SMSQuery = New WqlObjectQuery(Query) > SMSSearcher = New ManagementObjectSearcher(SMSScope, SMSQuery) > > Return SMSSearcher.Get > > Catch ex As Exception > Return Nothing > End Try > > End Function > _______________________________________________________ > > > > So here is my code for WbemScripting... > _______________________________________________________ > > Private Locator As SWbemLocator > Private Server As SWbemServices > Public SMSMainSite As String > > Public Function Connect(ByVal SMSServer As String) As Boolean > > Try > > Locator = New SWbemLocator > Server = Locator.ConnectServer(SMSServer, "root\sms") > > Catch ex As Exception > > Return False > > End Try > > Dim Sites As SWbemObjectSet > Dim Site As SWbemObject > > Try > > Sites = Server.ExecQuery("Select SiteCode From > SMS_ProviderLocation Where ProviderForLocalSite=True") > > For Each Site In Sites > SMSMainSite = Site.SiteCode > Next > > Server = Locator.ConnectServer(SMSServer, "root\sms\site_" & > SMSMainSite) > > Catch ex As Exception > > Return False > > End Try > > Return True > > End Function > > Public Function DeleteCollectionRules(ByVal CollectionID As String) As Boolean > > Dim Collection As SWbemObject > Dim Prop As SWbemProperty > Dim Rules() As Object > > Dim Method As SWbemMethod > Dim Parameters As SWbemObject > Try > > Collection = Server.Get("SMS_Collection='" & CollectionID & "'") > > Prop = Collection.Properties_.Item("CollectionRules") > If Not Prop.Value Is System.DBNull.Value Then Rules = Prop.Value > > If Not IsNothing(Rules) Then > Method = Collection.Methods_.Item("DeleteMembershipRules") > Parameters = Method.InParameters.SpawnInstance_ > Parameters.Properties_.Item("collectionRules").Value = Rules > Collection.ExecMethod_("DeleteMembershipRules", Parameters) > End If > Catch ex As Exception > Return False > End Try > > Return True > > End Function > > _______________________________________________________ > > Thanks! > > ShrimpyOne > >
Distributed Programming
Rewriting the Textbox Obscure error CHM file with .NET Registering hot-keys for your Winform DatagridView comboboxcolumn - assign cell value Adding new row to table in DataGridView Newbie Needs Help ! Find out the MAC-Adress of a server How to have .net code call pager or phone |
|||||||||||||||||||||||