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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s