Hello Everyone,

I am trying to stop a remote service using WMI however I am having some problems. I get false information back from the server, if the service is running it gives the state information as stopped. Here is my code:

ConnectionOptions op = new ConnectionOptions();
op.Username = username;
op.Password = password;
op.Impersonation = ImpersonationLevel.Impersonate;

ManagementScope scope = new ManagementScope("\\\\128.1.1.254\\root\\CIMV2", op);
try
{
scope.Connect();

label1.Text = "WMI connection established" + Environment.NewLine + "Connection Status: " + scope.IsConnected.ToString();
ManagementObject serviceobj1 = new ManagementObject("Win32_Service.Name='aspnet_state'");
serviceobj1.Get();
label1.Text = label1.Text + Environment.NewLine + serviceobj1["StartMode"].ToString() + Environment.NewLine + serviceobj1["State"].ToString();


label1.Text = label1.Text + Environment.NewLine + " Stopping ASP State Service.....";

InvokeMethodOptions invkop = new InvokeMethodOptions();
ManagementBaseObject outParams = serviceobj1.InvokeMethod("StopService", null, invkop);
label1.Text = label1.Text + Environment.NewLine + "Result: " + outParams["ReturnValue"];

}
catch (Exception ex)
{
label2.Text = ex.Message;
}

I am connecting as a local admin, also I get a result value of '5', this is not documented either.

Any ideas?