473,545 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Manageme nt 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.Manageme nt...

My problem is that with System.Manageme nt 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.Manageme nt

The only way I know is doing a For Each of what is being returned from
something like...
_______________ _______________ _______________ __________

Private Function GetObjects(ByVa l Query As String) As
ManagementObjec tCollection

Dim SMSObject As ManagementObjec t
Dim SMSSearcher As ManagementObjec tSearcher
Dim SMSQuery As ManagementQuery

Try

SMSQuery = New WqlObjectQuery( Query)
SMSSearcher = New ManagementObjec tSearcher(SMSSc ope, 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.Connect Server(SMSServe r, "root\sms")

Catch ex As Exception

Return False

End Try

Dim Sites As SWbemObjectSet
Dim Site As SWbemObject

Try

Sites = Server.ExecQuer y("Select SiteCode From
SMS_ProviderLoc ation Where ProviderForLoca lSite=True")

For Each Site In Sites
SMSMainSite = Site.SiteCode
Next

Server = Locator.Connect Server(SMSServe r, "root\sms\site_ " &
SMSMainSite)

Catch ex As Exception

Return False

End Try

Return True

End Function

Public Function DeleteCollectio nRules(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.Prop erties_.Item("C ollectionRules" )
If Not Prop.Value Is System.DBNull.V alue Then Rules = Prop.Value

If Not IsNothing(Rules ) Then
Method = Collection.Meth ods_.Item("Dele teMembershipRul es")
Parameters = Method.InParame ters.SpawnInsta nce_
Parameters.Prop erties_.Item("c ollectionRules" ).Value = Rules
Collection.Exec Method_("Delete MembershipRules ", Parameters)
End If
Catch ex As Exception
Return False
End Try

Return True

End Function

_______________ _______________ _______________ __________

Thanks!

ShrimpyOne
Jun 27 '06 #1
1 6292
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.Manageme nt...

My problem is that with System.Manageme nt 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.Manageme nt

The only way I know is doing a For Each of what is being returned from
something like...
_______________ _______________ _______________ __________

Private Function GetObjects(ByVa l Query As String) As
ManagementObjec tCollection

Dim SMSObject As ManagementObjec t
Dim SMSSearcher As ManagementObjec tSearcher
Dim SMSQuery As ManagementQuery

Try

SMSQuery = New WqlObjectQuery( Query)
SMSSearcher = New ManagementObjec tSearcher(SMSSc ope, 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.Connect Server(SMSServe r, "root\sms")

Catch ex As Exception

Return False

End Try

Dim Sites As SWbemObjectSet
Dim Site As SWbemObject

Try

Sites = Server.ExecQuer y("Select SiteCode From
SMS_ProviderLoc ation Where ProviderForLoca lSite=True")

For Each Site In Sites
SMSMainSite = Site.SiteCode
Next

Server = Locator.Connect Server(SMSServe r, "root\sms\site_ " &
SMSMainSite)

Catch ex As Exception

Return False

End Try

Return True

End Function

Public Function DeleteCollectio nRules(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.Prop erties_.Item("C ollectionRules" )
If Not Prop.Value Is System.DBNull.V alue Then Rules = Prop.Value

If Not IsNothing(Rules ) Then
Method = Collection.Meth ods_.Item("Dele teMembershipRul es")
Parameters = Method.InParame ters.SpawnInsta nce_
Parameters.Prop erties_.Item("c ollectionRules" ).Value = Rules
Collection.Exec Method_("Delete MembershipRules ", 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
14009
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 the workstations are DELLs running XP SP1a with the 1.1 .NET Framework. The following line of code generates an exception on the one PC: Dim oMac...
1
5907
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 "Management" does not exist in the class or namespace "System" How do I go about accessing the "Management" namespace... I am trying to get the Serial...
1
10225
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 mo As Management.ManagementObject moSearch = New Management.ManagementObjectSearcher("Select * from Win32_Printer")
7
6691
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 the System.Management namespace. This is where my problem is, I have no System.Management namespace. Could anyone help me locate it or a reference...
1
1645
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 data in our SMS Server... Now, when I tried to create my assembly I got this message... "Unable to emit assembly: Referenced assembly...
3
23296
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 help file, this 'System.Management.ManagementClass' is under System.Object, so I put in the Imports System.Object in namespace, but that seems...
8
5738
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 the same domain i start the collection on the remote machine i can get some 19 services without a problem then it will fail with: ...
5
2505
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 activeX might not work with mozilla. var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); Please anyone tell me the alternative...
2
4624
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 install it, the codes are copied to the virtual directory under Inetpub. when i try to edit the web.config file it throws an exception access is denied...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7808
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5329
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
704
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.