Service API

pysc.create(service_name, cmd[, username=None[, password=None]])

Create service.

Parameters:
  • service_name (str) – The name of the service to install.
  • cmd (list or str) – The fully qualified path to the service binary file. The path can also include arguments for an auto-start service.
  • username (str or None :platform: Windows) – The name of the account under which the service should run. Default uses the LocalSystem account.
  • password (str or None :platform: Windows) – The password to the account name specified by the username parameter.
Raises:

WinError – if the GetLastError return non zero value.

pysc.delete(service_name)

Delete service.

Parameters:service_name (str) – The name of the service.
pysc.start(service_name)

Start service.

Parameters:service_name (str) – The name of the service.
pysc.stop(service_name)

Stop service.

Parameters:service_name (str) – The name of the service.
pysc.event_stop(close_func)

Specify a function for stop the process of a service.

Parameters:close_func – A function is necessary to stop the process.
pysc.set_user(username[, password=None[, service_name=None]])

Specify name and password of the account to run service.

Platform:

Windows

Parameters:
  • username (str) – The name of the account under which the service should run. Default uses the LocalSystem account.
  • password (str or None) – The password to the account name specified by the username parameter.
  • service_name – The name of the service.

Note

On Windows if you specify user name to run service, you should add the “Log on as a service” right to an account on your local computer. (Local Security Policy -> Local Policies -> User Rights Assignment -> Log on as a service).