Index: src/libs/zbxcomms/comms.c
===================================================================
--- src/libs/zbxcomms/comms.c	(revision 90146)
+++ src/libs/zbxcomms/comms.c	(revision 90226)
@@ -185,41 +185,6 @@
 
 /******************************************************************************
  *                                                                            *
- * Function: zbx_socket_start                                                 *
- *                                                                            *
- * Purpose: Initialize Windows Sockets APIs                                   *
- *                                                                            *
- * Return value: SUCCEED or FAIL - an error occurred                          *
- *                                                                            *
- * Author: Eugene Grigorjev                                                   *
- *                                                                            *
- ******************************************************************************/
-#if defined(_WINDOWS)
-
-#define ZBX_SOCKET_START()	if (FAIL == socket_started) socket_started = zbx_socket_start()
-
-int	socket_started = FAIL;	/* winXX threads require socket_started not to be static */
-
-static int	zbx_socket_start()
-{
-	WSADATA	sockInfo;
-	int	ret;
-
-	if (0 != (ret = WSAStartup(MAKEWORD(2, 2), &sockInfo)))
-	{
-		zabbix_log(LOG_LEVEL_WARNING, "WSAStartup() failed: %s", strerror_from_system(ret));
-		return FAIL;
-	}
-
-	return SUCCEED;
-}
-
-#else
-#	define ZBX_SOCKET_START()
-#endif
-
-/******************************************************************************
- *                                                                            *
  * Function: zbx_socket_clean                                                 *
  *                                                                            *
  * Purpose: initialize socket                                                 *
@@ -459,8 +424,6 @@
 		return FAIL;
 	}
 #endif
-	ZBX_SOCKET_START();
-
 	zbx_socket_clean(s);
 
 	zbx_snprintf(service, sizeof(service), "%hu", port);
@@ -566,8 +529,6 @@
 		return FAIL;
 	}
 #endif
-	ZBX_SOCKET_START();
-
 	zbx_socket_clean(s);
 
 	if (NULL == (hp = gethostbyname(ip)))
@@ -894,8 +855,6 @@
 		no_inherit_wsapi = IsWindows7SP1OrGreater() || (IsWindowsServer() && IsWindows7OrGreater());
 #endif
 
-	ZBX_SOCKET_START();
-
 	zbx_socket_clean(s);
 
 	memset(&hints, 0, sizeof(hints));
@@ -1092,8 +1051,6 @@
 		no_inherit_wsapi = IsWindows7SP1OrGreater() || (IsWindowsServer() && IsWindows7OrGreater());
 #endif
 
-	ZBX_SOCKET_START();
-
 	zbx_socket_clean(s);
 
 	ip = ips = (NULL == listen_ip ? NULL : strdup(listen_ip));
Index: src/libs/zbxsysinfo/win32/hostname.c
===================================================================
--- src/libs/zbxsysinfo/win32/hostname.c	(revision 90146)
+++ src/libs/zbxsysinfo/win32/hostname.c	(revision 90226)
@@ -29,8 +29,7 @@
 	DWORD	dwSize = 256;
 	wchar_t	computerName[256];
 	char	*type, buffer[256];
-	int	netbios, rc;
-	WSADATA sockInfo;
+	int	netbios;
 
 	if (1 < request->nparam)
 	{
@@ -67,15 +66,8 @@
 	}
 	else
 	{
-		if (0 != (rc = WSAStartup(MAKEWORD(2, 2), &sockInfo)))
+		if (SUCCEED != gethostname(buffer, sizeof(buffer)))
 		{
-			zabbix_log(LOG_LEVEL_ERR, "WSAStartup() failed: %s", strerror_from_system(rc));
-			SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot initialize Winsock DLL: %s",
-					strerror_from_system(rc)));
-			return SYSINFO_RET_FAIL;
-		}
-		else if (SUCCEED != gethostname(buffer, sizeof(buffer)))
-		{
 			zabbix_log(LOG_LEVEL_ERR, "gethostname() failed: %s", strerror_from_system(WSAGetLastError()));
 			SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain host name: %s",
 					strerror_from_system(WSAGetLastError())));
Index: src/zabbix_agent/zabbix_agentd.c
===================================================================
--- src/zabbix_agent/zabbix_agentd.c	(revision 90146)
+++ src/zabbix_agent/zabbix_agentd.c	(revision 90226)
@@ -1086,6 +1086,10 @@
 #if defined(PS_OVERWRITE_ARGV)
 	setproctitle_free_env();
 #endif
+#ifdef _WINDOWS
+	while (0 == WSACleanup())
+		;
+#endif
 
 	exit(EXIT_SUCCESS);
 }
@@ -1112,6 +1116,17 @@
 
 	import_symbols();
 
+#ifdef _WINDOWS
+	WSADATA		sockInfo;
+
+	if (ZBX_TASK_SHOW_USAGE != t.task && ZBX_TASK_SHOW_VERSION != t.task && ZBX_TASK_SHOW_HELP != t.task &&
+			0 != (ret = WSAStartup(MAKEWORD(2, 2), &sockInfo)))
+	{
+		zbx_error("Cannot initialize Winsock DLL: %s", strerror_from_system(ret));
+		exit(EXIT_FAILURE);
+	}
+#endif
+
 	/* this is needed to set default hostname in zbx_load_config() */
 	init_metrics();
 
@@ -1146,6 +1161,10 @@
 			zbx_free_config();
 
 			ret = zbx_exec_service_task(argv[0], &t);
+
+			while (0 == WSACleanup())
+				;
+
 			free_metrics();
 			exit(SUCCEED == ret ? EXIT_SUCCESS : EXIT_FAILURE);
 			break;
@@ -1175,6 +1194,9 @@
 				test_parameters();
 #ifdef _WINDOWS
 			free_perf_collector();	/* cpu_collector must be freed before perf_collector is freed */
+
+			while (0 == WSACleanup())
+				;
 #endif
 #ifndef _WINDOWS
 			unload_modules();
