D
David Clegg
I initially posted this to .Framework.WMI a week ago but am yet to have
a response...
I am having trouble changing properties of a Windows Service
application using the ManagementObject class (in particular the
StartMode property). I can change the property and calling
ManagementObject.Put doesn't throw any exceptions, but the setting
isn't changed. If I query the property after setting and putting, it
appears to be updated, but if you create a new ManagementObject
instance to retrieve the details again, the old property is returned.
What am I missing here? I have pasted some code below to demonstrate.
//***BEGIN CODE***
using System;
using System.Management;
namespace MOTest {
class MOTest {
static void Main(string[] args) {
string objectPath = "Win32_Service.Name='ebetCJMSvc'";
ManagementObject mo = new ManagementObject(objectPath);
if (mo != null) {
ShowStartMode(mo, "Before Put:");
if (mo["StartMode"].ToString() == "Manual")
mo["StartMode"] = "Auto";
else
mo["StartMode"] = "Manual";
ManagementPath mp = mo.Put();
ShowStartMode(mo, "After Put:");
ShowStartMode(objectPath, "After Reload:");
Console.WriteLine("Press Enter to continue...");
Console.ReadLine();
}
}
static private void ShowStartMode(ManagementObject mo, string prefix)
{
if (mo != null) {
Console.WriteLine("{0} {1}", prefix, mo["StartMode"].ToString());
}
}
static private void ShowStartMode(string objectPath, string prefix) {
ManagementObject mo = new ManagementObject(objectPath);
ShowStartMode(mo, prefix);
}
}
}
//***END CODE***
a response...
I am having trouble changing properties of a Windows Service
application using the ManagementObject class (in particular the
StartMode property). I can change the property and calling
ManagementObject.Put doesn't throw any exceptions, but the setting
isn't changed. If I query the property after setting and putting, it
appears to be updated, but if you create a new ManagementObject
instance to retrieve the details again, the old property is returned.
What am I missing here? I have pasted some code below to demonstrate.
//***BEGIN CODE***
using System;
using System.Management;
namespace MOTest {
class MOTest {
static void Main(string[] args) {
string objectPath = "Win32_Service.Name='ebetCJMSvc'";
ManagementObject mo = new ManagementObject(objectPath);
if (mo != null) {
ShowStartMode(mo, "Before Put:");
if (mo["StartMode"].ToString() == "Manual")
mo["StartMode"] = "Auto";
else
mo["StartMode"] = "Manual";
ManagementPath mp = mo.Put();
ShowStartMode(mo, "After Put:");
ShowStartMode(objectPath, "After Reload:");
Console.WriteLine("Press Enter to continue...");
Console.ReadLine();
}
}
static private void ShowStartMode(ManagementObject mo, string prefix)
{
if (mo != null) {
Console.WriteLine("{0} {1}", prefix, mo["StartMode"].ToString());
}
}
static private void ShowStartMode(string objectPath, string prefix) {
ManagementObject mo = new ManagementObject(objectPath);
ShowStartMode(mo, prefix);
}
}
}
//***END CODE***