Problem with WMI

M

MollocH

Hi NG,

Here some Code:

------------------------------------------------------
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim myPath As Management.ManagementPath = New Management.ManagementPath

myPath.Server = System.Environment.MachineName

myPath.NamespacePath = "root\CIMV2"

myPath.RelativePath = "Win32_Service.Name='Messenger'"

Dim myService As Management.ManagementObject = New
Management.ManagementObject(myPath)

Dim myvalue As String = "Testit"

MsgBox(myService.GetPropertyValue("DisplayName"))

myService.SetPropertyValue("DisplayName", myvalue)

myService.Put()

MsgBox(myService.GetPropertyValue("DisplayName"))

End Sub

End Class
-------------------------------------------------------

The first msgbox shows the initial value and the second shows the new value
.... but in services.msc nothing changes ...

have tried anything ... also can't bring the .invokemethod("change",args) to
work ...

Anyone an idea ?

Thx & greetings
 
M

MollocH

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim classInstance As New Management.ManagementObject( _

"root\CIMV2", _

"Win32_Service.Name='Messenger'", _

Nothing)

Dim inParams As Management.ManagementBaseObject = _

classInstance.GetMethodParameters("Change")

inParams("StartMode") = "Manual"

Dim outParams As Management.ManagementBaseObject = _

classInstance.InvokeMethod("Change", inParams, Nothing)

Console.WriteLine("Out parameters:")

Console.WriteLine("ReturnValue: {0}", outParams("ReturnValue"))

End Sub

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top