Start and stop a service
<p>I am using the following code fragment to change the account and password credentials of a Windows Service. However, this only works if the service is stopped.</p>

<p>How can I, programatically, stop the service before making these changes, and then start it again?</p>

<pre><code>namespace ServiceAccount
{
    class Program
    {
        static void Main(string[] args)
        {
            string serviceName = "DummyService";
            string username = ".\\Service_Test";
            string password = "Password1";

            string objPath = string.Format("Win32_Service.Name='{0}'", serviceName);
            using (ManagementObject service = new ManagementObject(new ManagementPath(objPath)))
            {
                object[] wmiParams = new object[11];
                wmiParams[6] = username;
                wmiParams[7] = password;
                service.InvokeMethod("Change", wmiParams);
            }

        }
    }
}
</code></pre>
