Example #1
0
 /// <summary>
 ///     Changes the configuration parameters of a service.
 /// </summary>
 /// <param name="serviceHandle">A handle to the service.</param>
 /// <param name="serviceType">
 ///     The type of service. Specify <see cref="AdvApi32.SERVICE_NO_CHANGE" /> if you are not
 ///     changing the existing service type.
 /// </param>
 /// <param name="startMode">
 ///     The service start options.  Specify <see cref="AdvApi32.SERVICE_NO_CHANGE" /> if you are not
 ///     changing the existing start options.
 /// </param>
 /// <param name="errorControl">
 ///     The severity of the error, and action taken, if this service fails to start. Specify
 ///     <see cref="AdvApi32.SERVICE_NO_CHANGE" /> if you are not changing the existing error control.
 /// </param>
 /// <param name="binaryPath">
 ///     The fully qualified path to the service binary file. Specify NULL if you are not changing the
 ///     existing path. If the path contains a space, it must be quoted so that it is correctly interpreted.
 /// </param>
 /// <param name="loadOrderGroup">
 ///     The name of the load ordering group of which this service is a member. Specify NULL if you
 ///     are not changing the existing group. Specify an empty string if the service does not belong to a group.
 /// </param>
 /// <param name="dependencies">
 ///     A pointer to a double null-terminated array of null-separated names of services or load
 ///     ordering groups that the system must start before this service can be started. (Dependency on a group means that
 ///     this service can run if at least one member of the group is running after an attempt to start all members of the
 ///     group.) Specify NULL if you are not changing the existing dependencies. Specify an empty string if the service has
 ///     no dependencies.
 /// </param>
 /// <param name="serviceStartName">
 ///     The name of the account under which the service should run. Specify NULL if you are not
 ///     changing the existing account name.
 /// </param>
 /// <param name="password">
 ///     The password to the account name specified by the lpServiceStartName parameter. Specify NULL if
 ///     you are not changing the existing password. Specify an empty string if the account has no password or if the
 ///     service runs in the LocalService, NetworkService, or LocalSystem account.
 /// </param>
 /// <param name="displayName">
 ///     The display name to be used by applications to identify the service for its users. Specify
 ///     NULL if you are not changing the existing display name.
 /// </param>
 private static void ChangeServiceConfig(SafeHandle serviceHandle, uint serviceType, uint startMode,
                                         uint errorControl, string binaryPath, string loadOrderGroup, string dependencies, string serviceStartName,
                                         string password, string displayName)
 {
     if (
         !NativeMethods.ChangeServiceConfig(serviceHandle, serviceType, startMode, errorControl, binaryPath,
                                            loadOrderGroup, 0, dependencies, serviceStartName, password, displayName))
     {
         throw new Win32Exception();
     }
 }