473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

System.Management VS WbemScripting

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").Val ue = Rules
Collection.ExecMethod_("DeleteMembershipRules", Parameters)
End If
Catch ex As Exception
Return False
End Try

Return True

End Function

__________________________________________________ _____

Thanks!

ShrimpyOne
Jun 27 '06 #1
1 6281
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.
"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").Val ue = Rules
Collection.ExecMethod_("DeleteMembershipRules", Parameters)
End If
Catch ex As Exception
Return False
End Try

Return True

End Function

__________________________________________________ _____

Thanks!

ShrimpyOne

Jul 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul Gronka | last post by:
I've got a VB.NET windows application (written in VS .NET 2003) that makes a call to WMI for retrieving the MAC Address from the client's PC. It works on 4 out of the 5 PC's tested so far. All...
1
by: PaulThomas | last post by:
I am using VS.Net 2000 and C# trying to access the System.Management namespace in a Web Application -but- after: using System; using System.Management; I get: The type or namespace name...
1
by: lcifers | last post by:
I have an application that uses the following code to return the default printer: Dim moReturn As Management.ManagementObjectCollection Dim moSearch As Management.ManagementObjectSearcher Dim...
7
by: eric | last post by:
I'm writing a program in C# and found a couple of threads about how to check the status of a printer before sending it any data, to ensure that the printer is ready to print. They say to include...
1
by: ShrimpBoy | last post by:
Hi! I'm using a Strong Name Key to create our assemblies, this key has the Full Trust security so we can use those "mini tools" from network drives... I'm trying to use WMI to get access to...
3
by: Anil Gupte | last post by:
I am getting this error: Type 'System.Management.ManagementClass' is not defined. The statement is: Dim diskClass As New System.Management.ManagementClass("Win32_LogicalDisk") According to the...
8
by: =?Utf-8?B?YXVsZGg=?= | last post by:
i trying to collect windows services. i'm getting inconsistencies. the collection works every time locally. but remote collection yields different result depending on my lab environment. 1) in...
5
by: thallasridevi | last post by:
Hello, I am trying to get system information. I found a script. When i tried it, it is working in internet explorer. But it is not working with mozilla. I think problem is with below statement as...
2
by: karthi84 | last post by:
Hi Experts, i have created a web application which has an option to edit the web config file from the web page. when i create an installer for this project using web setup project in VS2008 and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.