Uploaded image for project: 'ZABBIX FEATURE REQUESTS'
  1. ZABBIX FEATURE REQUESTS
  2. ZBXNEXT-5977

Registering Zabbix agent for Windows as "Automatic (delayed start)" service

XMLWordPrintable

    • S24-W16/17
    • 2

      Automatic (delayed start) is available on Windows Vista / 2008 or later.
      Most of the troubles of Zabbix agent when the OS is restarted on Windows, the service startup is "Automatic". In that case, "Automatic (delayed start)" will solve the problem.
      I think it's better to set fDelayedAutostart of SERVICE_CONFIG_DELAYED_AUTO_START_INFO to TRUE with ChangeServiceConfig2 function below.

      int	ZabbixCreateService(const char *path, int multiple_agents)
      {
      	SC_HANDLE		mgr, service;
      	SERVICE_DESCRIPTION	sd;
      // Add Start
      	const OSVERSIONINFOEX	*vi;
      	SERVICE_DELAYED_AUTO_START_INFO	scdasi;
      // Add End
      	wchar_t			cmdLine[MAX_PATH];
      	wchar_t			*wservice_name;
      	DWORD			code;
      	int			ret = FAIL;
      
      	if (FAIL == svc_OpenSCManager(&mgr))
      		return ret;
      
      	svc_get_command_line(path, multiple_agents, cmdLine, MAX_PATH);
      
      	wservice_name = zbx_utf8_to_unicode(ZABBIX_SERVICE_NAME);
      
      	if (NULL == (service = CreateService(mgr, wservice_name, wservice_name, GENERIC_READ, SERVICE_WIN32_OWN_PROCESS,
      			SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, cmdLine, NULL, NULL, NULL, NULL, NULL)))
      	{
      		if (ERROR_SERVICE_EXISTS == (code = GetLastError()))
      			zbx_error("ERROR: service [%s] already exists", ZABBIX_SERVICE_NAME);
      		else
      			zbx_error("ERROR: cannot create service [%s]: %s", ZABBIX_SERVICE_NAME, strerror_from_system(code));
      	}
      	else
      	{
      		zbx_error("service [%s] installed successfully", ZABBIX_SERVICE_NAME);
      		CloseServiceHandle(service);
      		ret = SUCCEED;
      
      		/* update the service description */
      		if (SUCCEED == svc_OpenService(mgr, &service, SERVICE_CHANGE_CONFIG))
      		{
      			sd.lpDescription = TEXT("Provides system monitoring");
      			if (0 == ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &sd))
      				zbx_error("service description update failed: %s", strerror_from_system(GetLastError()));
      // Add Start
      			if (NULL != (vi = zbx_win_getversion()) && 6 <= vi->dwMajorVersion)
      			{
      					scdasi.fDelayedAutostart = TRUE;
      					if (0 == ChangeServiceConfig2(service, SERVICE_CONFIG_DELAYED_AUTO_START_INFO, &scdasi))
      						zbx_error("service start update failed: %s", strerror_from_system(GetLastError()));
      			}
      // Add End
      			CloseServiceHandle(service);
      		}
      	}
      
      	zbx_free(wservice_name);
      
      	CloseServiceHandle(mgr);
      
      	if (SUCCEED == ret)
      		ret = svc_install_event_source(path);
      
      	return ret;
      }
      

      I changed and confirmed the source of Zabbix 3.0.30.
      I was able to "Automatic (delayed start)" on Windows 10.

            lgrigorjeva Larisa Grigorjeva
            kazuo.ito Kazuo Ito
            Team B
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: