Changing Service Startup Type

It seems to me that ServiceController class (the once I used to manage my services) doesn’t support this kind of functionality.

After googling, I found this

Basically, we have to use WMI for this task. Below is the sample code

public static void SetServiceStartupType(string serviceName, 
   StartupType startupType)
   // construct the management path
   string path = string.Format("Win32_Service.Name='{0}'", serviceName);
   ManagementPath mPath = new ManagementPath(path);

   // construct the management object
   ManagementObject obj = new ManagementObject(mPath);

   object[] parameters = new object[1];
   parameters[0] = startupType.ToString();
   obj.InvokeMethod("ChangeStartMode", parameters);

There is a very good tool to generate WMI code that we can download from