salt.modules.win_service

Windows Service module.

salt.modules.win_service.available(name)

Returns True if the specified service is available, otherwise returns False.

CLI 范例:

salt '*' service.available <service name>
salt.modules.win_service.config(name, bin_path=None, display_name=None, svc_type=None, start_type=None, error=None, group=None, tag=None, depend=None, obj=None, password=None, **kwargs)

Modify the named service.

2015.8.8 新版功能.

Required parameters:

参数:name (str) -- Specifies the service name returned by the getkeyname

operation

Optional parameters:

参数:bin_path (str) -- Specifies the path to the service binary file,

backslashes must be escaped - eg: C:\path\to\binary.exe

参数:display_name (str) -- the name to be displayed in the service manager

Specifies a more descriptive name for identifying the service in user interface programs.

参数:
  • svc_type (str) --

    Specifies the service type. Acceptable values are: - own (default): Service runs in its own process - share: Service runs as a shared process - interact: Service can interact with the desktop - kernel: Service is a driver - filesys: Service is a system driver - rec: Service is a file system-recognized driver that identifies

    filesystems on the computer
    • adapt: Service is an adapter driver that identifies hardware such as keyboards, mice and disk drives
  • start_type (str) -- Specifies the start type for the service.
Acceptable values are:
  • boot: Device driver that is loaded by the boot loader
  • system: Device driver that is started during kernel initialization
  • auto: Service that automatically starts
  • demand (default): Service must be started manually
  • disabled: Service cannot be started
  • delayed-auto: Service starts automatically after other auto-services start
参数:error (str) -- Specifies the severity of the error if the service
fails to start. Acceptable values are:
  • normal (default): Error is logged and a message box is displayed
  • severe: Error is logged and computer attempts a restart with last known good configuration
  • critical: Error is logged, computer attempts to restart with last known good configuration, system halts on failure
  • ignore: Error is logged and startup continues, no notification is given to the user
参数:group (str) -- Specifies the name of the group of which this service is a

member. The list of groups is stored in the registry, in the HKLMSystemCurrentControlSetControlServiceGroupOrder subkey. The default is null.

参数:tag (str) -- Specifies whether or not to obtain a TagID from the

CreateService call. For boot-start and system-start drivers only. Acceptable values are:

  • yes/no
参数:depend (str) -- Specifies the names of services or groups that must start

before this service. The names are separated by forward slashes.

参数:obj (str) -- Specifies th name of an account in which a service will run

or specifies a name of the Windows driver object in which the driver will run. Default is LocalSystem

参数:password (str) -- Specifies a password. Required if other than

LocalSystem account is used.

返回:True if successful, False if not
返回类型:bool

CLI 范例:

salt '*' service.config <service name> <path to exe> display_name='<display name>'
salt.modules.win_service.create(name, binpath, DisplayName=None, type='own', start='demand', error='normal', group=None, tag='no', depend=None, obj=None, password=None, **kwargs)

Create the named service.

2015.8.0 新版功能.

Required parameters:

参数:
  • name -- Specifies the service name returned by the getkeyname operation
  • binpath -- Specifies the path to the service binary file, backslashes must be escaped - eg: C:\path\to\binary.exe

Optional parameters:

参数:
  • DisplayName -- the name to be displayed in the service manager
  • type -- Specifies the service type, default is own - own (default): Service runs in its own process - share: Service runs as a shared process - interact: Service can interact with the desktop - kernel: Service is a driver - filesys: Service is a system driver - rec: Service is a file system-recognized driver that identifies filesystems on the computer
  • start -- Specifies the start type for the service - boot: Device driver that is loaded by the boot loader - system: Device driver that is started during kernel initialization - auto: Service that automatically starts - demand (default): Service must be started manually - disabled: Service cannot be started - delayed-auto: Service starts automatically after other auto-services start
  • error -- Specifies the severity of the error - normal (default): Error is logged and a message box is displayed - severe: Error is logged and computer attempts a restart with last known good configuration - critical: Error is logged, computer attempts to restart with last known good configuration, system halts on failure - ignore: Error is logged and startup continues, no notification is given to the user
  • group -- Specifies the name of the group of which this service is a member
  • tag -- Specifies whether or not to obtain a TagID from the CreateService call. For boot-start and system-start drivers - yes/no
  • depend -- Specifies the names of services or groups that myust start before this service. The names are separated by forward slashes.
  • obj -- Specifies th ename of an account in which a service will run. Default is LocalSystem
  • password -- Specifies a password. Required if other than LocalSystem account is used.

CLI 范例:

salt '*' service.create <service name> <path to exe> display_name='<display name>'
salt.modules.win_service.create_win_salt_restart_task()

Create a task in Windows task scheduler to enable restarting the salt-minion

CLI 范例:

salt '*' service.create_win_salt_restart_task()
salt.modules.win_service.delete(name)

Delete the named service

CLI 范例:

salt '*' service.delete <service name>
salt.modules.win_service.disable(name, **kwargs)

Disable the named service to start at boot

CLI 范例:

salt '*' service.disable <service name>
salt.modules.win_service.disabled(name)

Check to see if the named service is disabled to start on boot

CLI 范例:

salt '*' service.disabled <service name>
salt.modules.win_service.enable(name, **kwargs)

Enable the named service to start at boot

CLI 范例:

salt '*' service.enable <service name>
salt.modules.win_service.enabled(name, **kwargs)

Check to see if the named service is enabled to start on boot

CLI 范例:

salt '*' service.enabled <service name>
salt.modules.win_service.execute_salt_restart_task()

Run the Windows Salt restart task

CLI 范例:

salt '*' service.execute_salt_restart_task()
salt.modules.win_service.get_all()

Return all installed services

CLI 范例:

salt '*' service.get_all
salt.modules.win_service.get_disabled()

Return the disabled services

CLI 范例:

salt '*' service.get_disabled
salt.modules.win_service.get_enabled()

Return the enabled services

CLI 范例:

salt '*' service.get_enabled
salt.modules.win_service.get_service_name(*args)

The Display Name is what is displayed in Windows when services.msc is executed. Each Display Name has an associated Service Name which is the actual name of the service. This function allows you to discover the Service Name by returning a dictionary of Display Names and Service Names, or filter by adding arguments of Display Names.

If no args are passed, return a dict of all services where the keys are the service Display Names and the values are the Service Names.

If arguments are passed, create a dict of Display Names and Service Names

CLI 范例:

salt '*' service.get_service_name
salt '*' service.get_service_name 'Google Update Service (gupdate)' 'DHCP Client'
salt.modules.win_service.getsid(name)

Return the sid for this windows service

CLI 范例:

salt '*' service.getsid <service name>
salt.modules.win_service.missing(name)

The inverse of service.available. Returns True if the specified service is not available, otherwise returns False.

CLI 范例:

salt '*' service.missing <service name>
salt.modules.win_service.restart(name)

Restart the named service

CLI 范例:

salt '*' service.restart <service name>
salt.modules.win_service.start(name)

Start the specified service

CLI 范例:

salt '*' service.start <service name>
salt.modules.win_service.status(name, sig=None)

Return the status for a service, returns the PID or an empty string if the service is running or not, pass a signature to use to find the service via ps

CLI 范例:

salt '*' service.status <service name> [service signature]
salt.modules.win_service.stop(name)

Stop the specified service

CLI 范例:

salt '*' service.stop <service name>