473,395 Members | 1,452 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,395 software developers and data experts.

System.Management.ManagementObject cannot set property.

I am using the System.Management namespace for the first time and I
cannot get the ManagementObject.SetPropertyValue method to work
properly.

I am trying to change the ServerName and ShareName of a printer, to
facilitate changing the print server of workstations remotely in the
event of a print server failure.

Thanks in advance for any assistance.
Here is my subroutine (None of the error catches are triggered in normal
execution, but the SetPropertyValue lines just seem to have no result at
all):

Private Sub btnSaveSetting_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSaveSetting.Click

Dim query As ManagementObjectSearcher
Dim queryCollection As ManagementObjectCollection
Dim co As ConnectionOptions
Dim oq As ObjectQuery
Dim ms As ManagementScope
Dim mo As ManagementObject
Dim strComputerName, strQuery As String

Dim sPrinterInfo As String = ""

lblComputer.Text = sComputerName + sPrinterName

If sPrinterName.Trim() = "" Then
Exit Sub
End If

strQuery = "SELECT * FROM Win32_Printer"

strComputerName = txtServerName.Text

Cursor.Current = Cursors.WaitCursor

co = New ConnectionOptions

If (strComputerName.Trim().Length = 0) Then

Cursor.Current = Cursors.Default

MessageBox.Show("Must enter machine IP address or name.")

Else

ms = New System.Management.ManagementScope("\\" + strComputerName +
"\root\cimv2", co)

oq = New System.Management.ObjectQuery(strQuery)

query = New ManagementObjectSearcher(ms, oq)

Try

queryCollection = query.Get()

Catch e1 As Exception

sendResult("Error: " + e1.ToString())

End Try

For Each mo In queryCollection

Try

If mo("Name").ToString() = sPrinterName Then

Try
mo.SetPropertyValue("Name", txtName.Text)
Catch ex As Exception
sendResult("Error: (Could not set Name) " + ex.ToString)
End Try

Try
mo.SetPropertyValue("ServerName", txtServer.Text)
Catch ex As Exception
sendResult("Error: (Could not set ServerName) " + ex.ToString)
End Try

Try
mo.SetPropertyValue("ShareName", cboxShareName.Text)
Catch ex As Exception
sendResult("Error: (Could not set ShareName) " + ex.ToString)
End Try

End If

Catch ex As Exception
sendResult("Error: " + ex.ToString())
End Try

Next

End If

Cursor.Current = Cursors.Default

GC.Collect()

End Sub
Nov 20 '05 #1
0 3898

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

Similar topics

1
by: ------------------ eric -------------------- | last post by:
Any idea how to reboot a givin machine useing the ststem.management namespace? thanks eric.
0
by: Ger | last post by:
Hi, I have a problem with a Windows Service that I have created accessing System.Management.dll on a W2k3 environment. The Service runs fine on an XP machine but the same Service causes an error...
0
by: Ben Reese | last post by:
Kind people on this discussion group have previously helped me to dynamically identify CD rom drives etc at runtime using objects in System.management +++++++++++++++++++++++++++++++++++++++ Dim...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
1
by: Tony Maresca | last post by:
Greetings. I would like to display the WMI properties for a printer in a PropertyGrid, with minimal coding. A WMI printer object is represented in managed code using the...
2
by: Lamis | last post by:
Hi, I need urgent help, this is my code to rename my hostName: (MY computer is not member of domain) string compName = System.Windows.Forms.SystemInformation.ComputerName.ToString();...
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...
0
by: =?Utf-8?B?am1hZ2FyYW0=?= | last post by:
I have a Windows service written in C# that is configured to automatically start. Sometimes - maybe 20% of the time - the service fails to start due to an exception in WMI code. I haven't made my...
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...
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.