CPU usage parameters on Windows moved to winnt.nsm from winperf.nsm and no longer...
[public/netxms.git] / src / agent / subagents / winnt / main.cpp
1 /*
2 ** Windows platform subagent
3 ** Copyright (C) 2003-2016 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: main.cpp
20 **
21 **/
22
23 #include "winnt_subagent.h"
24 #include "lm.h"
25
26 /**
27 * Externlals
28 */
29 LONG H_ActiveUserSessions(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
30 LONG H_AgentDesktop(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
31 LONG H_AppAddressSpace(const TCHAR *pszCmd, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session);
32 LONG H_ArpCache(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
33 LONG H_ConnectedUsers(const TCHAR *pszCmd, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session);
34 LONG H_CPUUsage(const TCHAR *param, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
35 LONG H_Desktops(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
36 LONG H_HandleCount(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
37 LONG H_InstalledProducts(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *);
38 LONG H_InterfaceList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
39 LONG H_InterfaceNames(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
40 LONG H_IPRoutingTable(const TCHAR *cmd, const TCHAR *arg, StringList *pValue, AbstractCommSession *session);
41 LONG H_NetInterface64bitSupport(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
42 LONG H_NetInterfaceStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
43 LONG H_NetIPStats(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
44 LONG H_RemoteShareStatus(const TCHAR *pszCmd, const TCHAR *pArg, TCHAR *pValue, AbstractCommSession *session);
45 LONG H_ProcessList(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
46 LONG H_ProcessTable(const TCHAR *cmd, const TCHAR *arg, Table *value, AbstractCommSession *);
47 LONG H_ProcCount(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
48 LONG H_ProcCountSpecific(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
49 LONG H_ProcInfo(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
50 LONG H_ServiceList(const TCHAR *pszCmd, const TCHAR *pArg, StringList *value, AbstractCommSession *session);
51 LONG H_ServiceState(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
52 LONG H_ServiceTable(const TCHAR *pszCmd, const TCHAR *pArg, Table *value, AbstractCommSession *session);
53 LONG H_SysUpdateTime(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
54 LONG H_ThreadCount(const TCHAR *cmd, const TCHAR *arg, TCHAR *value, AbstractCommSession *session);
55 LONG H_WindowStations(const TCHAR *cmd, const TCHAR *arg, StringList *value, AbstractCommSession *session);
56
57 void StartCPUStatCollector();
58 void StopCPUStatCollector();
59
60 /**
61 * Optional imports
62 */
63 DWORD (__stdcall *imp_GetIfEntry2)(PMIB_IF_ROW2) = NULL;
64
65 /**
66 * Windows XP/Windows Server 2003 flag
67 */
68 bool g_isWin5 = false;
69
70 /**
71 * Import symbols
72 */
73 static void ImportSymbols()
74 {
75 HMODULE hModule;
76
77 // IPHLPAPI.DLL
78 hModule = LoadLibrary(_T("IPHLPAPI.DLL"));
79 if (hModule != NULL)
80 {
81 imp_GetIfEntry2 = (DWORD (__stdcall *)(PMIB_IF_ROW2))GetProcAddress(hModule, "GetIfEntry2");
82 }
83 else
84 {
85 AgentWriteLog(NXLOG_WARNING, _T("Unable to load IPHLPAPI.DLL"));
86 }
87 }
88
89 /**
90 * Set or clear current privilege
91 */
92 static BOOL SetCurrentPrivilege(LPCTSTR pszPrivilege, BOOL bEnablePrivilege)
93 {
94 HANDLE hToken;
95 LUID luid;
96 TOKEN_PRIVILEGES tp, tpPrevious;
97 DWORD cbPrevious = sizeof(TOKEN_PRIVILEGES);
98 BOOL bSuccess = FALSE;
99
100 if (!LookupPrivilegeValue(NULL, pszPrivilege, &luid))
101 return FALSE;
102
103 if(!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &hToken))
104 return FALSE;
105
106 tp.PrivilegeCount = 1;
107 tp.Privileges[0].Luid = luid;
108 tp.Privileges[0].Attributes = 0;
109
110 if (AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
111 &tpPrevious, &cbPrevious))
112 {
113 tpPrevious.PrivilegeCount = 1;
114 tpPrevious.Privileges[0].Luid = luid;
115
116 if (bEnablePrivilege)
117 tpPrevious.Privileges[0].Attributes |= SE_PRIVILEGE_ENABLED;
118 else
119 tpPrevious.Privileges[0].Attributes &= ~SE_PRIVILEGE_ENABLED;
120
121 bSuccess = AdjustTokenPrivileges(hToken, FALSE, &tpPrevious, cbPrevious, NULL, NULL);
122 }
123
124 CloseHandle(hToken);
125
126 return bSuccess;
127 }
128
129 /**
130 * Shutdown system
131 */
132 static LONG H_ActionShutdown(const TCHAR *action, StringList *args, const TCHAR *data, AbstractCommSession *session)
133 {
134 LONG nRet = ERR_INTERNAL_ERROR;
135
136 if (SetCurrentPrivilege(SE_SHUTDOWN_NAME, TRUE))
137 {
138 if (InitiateSystemShutdown(NULL, NULL, 0, TRUE, (*data == _T('R')) ? TRUE : FALSE))
139 nRet = ERR_SUCCESS;
140 }
141 return nRet;
142 }
143
144 /**
145 * Change user's password
146 * Parameters: user new_password
147 */
148 static LONG H_ChangeUserPassword(const TCHAR *action, StringList *args, const TCHAR *data, AbstractCommSession *session)
149 {
150 if (args->size() < 2)
151 return ERR_INTERNAL_ERROR;
152
153 USER_INFO_1003 ui;
154 ui.usri1003_password = (TCHAR *)args->get(1);
155 NET_API_STATUS status = NetUserSetInfo(NULL, args->get(0), 1003, (LPBYTE)&ui, NULL);
156 AgentWriteDebugLog(2, _T("WINNT: change password for user %s status=%d"), args->get(0), status);
157 return (status == NERR_Success) ? ERR_SUCCESS : ERR_INTERNAL_ERROR;
158 }
159
160 /**
161 * Subagent initialization
162 */
163 static BOOL SubAgentInit(Config *config)
164 {
165 StartCPUStatCollector();
166 return true;
167 }
168
169 /**
170 * Called by master agent at unload
171 */
172 static void SubAgentShutdown()
173 {
174 StopCPUStatCollector();
175 }
176
177 /**
178 * Supported parameters
179 */
180 static NETXMS_SUBAGENT_PARAM m_parameters[] =
181 {
182 { _T("Agent.Desktop"), H_AgentDesktop, NULL, DCI_DT_STRING, _T("Desktop associated with agent process") },
183 { _T("Net.Interface.64BitCounters"), H_NetInterface64bitSupport, NULL, DCI_DT_INT, DCIDESC_NET_INTERFACE_64BITCOUNTERS },
184 { _T("Net.Interface.AdminStatus(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_ADMIN_STATUS, DCI_DT_INT, DCIDESC_NET_INTERFACE_ADMINSTATUS },
185 { _T("Net.Interface.BytesIn(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_BYTES_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESIN },
186 { _T("Net.Interface.BytesIn64(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_BYTES_IN_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESIN },
187 { _T("Net.Interface.BytesOut(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_BYTES_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_BYTESOUT },
188 { _T("Net.Interface.BytesOut64(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_BYTES_OUT_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_BYTESOUT },
189 { _T("Net.Interface.Description(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_DESCR, DCI_DT_STRING, DCIDESC_NET_INTERFACE_DESCRIPTION },
190 { _T("Net.Interface.InErrors(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_IN_ERRORS, DCI_DT_UINT, DCIDESC_NET_INTERFACE_INERRORS },
191 { _T("Net.Interface.Link(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_OPER_STATUS, DCI_DT_DEPRECATED, DCIDESC_DEPRECATED },
192 { _T("Net.Interface.MTU(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_MTU, DCI_DT_UINT, DCIDESC_NET_INTERFACE_MTU },
193 { _T("Net.Interface.OperStatus(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_OPER_STATUS, DCI_DT_INT, DCIDESC_NET_INTERFACE_OPERSTATUS },
194 { _T("Net.Interface.OutErrors(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_OUT_ERRORS, DCI_DT_UINT, DCIDESC_NET_INTERFACE_OUTERRORS },
195 { _T("Net.Interface.PacketsIn(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_PACKETS_IN, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSIN },
196 { _T("Net.Interface.PacketsIn64(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_PACKETS_IN_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSIN },
197 { _T("Net.Interface.PacketsOut(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_PACKETS_OUT, DCI_DT_UINT, DCIDESC_NET_INTERFACE_PACKETSOUT },
198 { _T("Net.Interface.PacketsOut64(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_PACKETS_OUT_64, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_PACKETSOUT },
199 { _T("Net.Interface.Speed(*)"), H_NetInterfaceStats, (TCHAR *)NETINFO_IF_SPEED, DCI_DT_UINT64, DCIDESC_NET_INTERFACE_SPEED },
200 { _T("Net.IP.Forwarding"), H_NetIPStats, (TCHAR *)NETINFO_IP_FORWARDING, DCI_DT_INT, DCIDESC_NET_IP_FORWARDING },
201 { _T("Net.RemoteShareStatus(*)"), H_RemoteShareStatus, _T("C"), DCI_DT_INT, _T("Status of remote shared resource") },
202 { _T("Net.RemoteShareStatusText(*)"), H_RemoteShareStatus, _T("T"), DCI_DT_STRING, _T("Status of remote shared resource as text") },
203 { _T("Process.Count(*)"), H_ProcCountSpecific, _T("N"), DCI_DT_INT, DCIDESC_PROCESS_COUNT },
204 { _T("Process.CountEx(*)"), H_ProcCountSpecific, _T("E"), DCI_DT_INT, DCIDESC_PROCESS_COUNTEX },
205 { _T("Process.CPUTime(*)"), H_ProcInfo, (TCHAR *)PROCINFO_CPUTIME, DCI_DT_UINT64, DCIDESC_PROCESS_CPUTIME },
206 { _T("Process.GDIObjects(*)"), H_ProcInfo, (TCHAR *)PROCINFO_GDI_OBJ, DCI_DT_UINT64, DCIDESC_PROCESS_GDIOBJ },
207 { _T("Process.Handles(*)"), H_ProcInfo, (TCHAR *)PROCINFO_HANDLES, DCI_DT_UINT, DCIDESC_PROCESS_HANDLES },
208 { _T("Process.IO.OtherB(*)"), H_ProcInfo, (TCHAR *)PROCINFO_IO_OTHER_B, DCI_DT_UINT64, DCIDESC_PROCESS_IO_OTHERB },
209 { _T("Process.IO.OtherOp(*)"), H_ProcInfo, (TCHAR *)PROCINFO_IO_OTHER_OP, DCI_DT_UINT64, DCIDESC_PROCESS_IO_OTHEROP },
210 { _T("Process.IO.ReadB(*)"), H_ProcInfo, (TCHAR *)PROCINFO_IO_READ_B, DCI_DT_UINT64, DCIDESC_PROCESS_IO_READB },
211 { _T("Process.IO.ReadOp(*)"), H_ProcInfo, (TCHAR *)PROCINFO_IO_READ_OP, DCI_DT_UINT64, DCIDESC_PROCESS_IO_READOP },
212 { _T("Process.IO.WriteB(*)"), H_ProcInfo, (TCHAR *)PROCINFO_IO_WRITE_B, DCI_DT_UINT64, DCIDESC_PROCESS_IO_WRITEB },
213 { _T("Process.IO.WriteOp(*)"), H_ProcInfo, (TCHAR *)PROCINFO_IO_WRITE_OP, DCI_DT_UINT64, DCIDESC_PROCESS_IO_WRITEOP },
214 { _T("Process.KernelTime(*)"), H_ProcInfo, (TCHAR *)PROCINFO_KTIME, DCI_DT_UINT64, DCIDESC_PROCESS_KERNELTIME },
215 { _T("Process.PageFaults(*)"), H_ProcInfo, (TCHAR *)PROCINFO_PF, DCI_DT_UINT64, DCIDESC_PROCESS_PAGEFAULTS },
216 { _T("Process.UserObjects(*)"), H_ProcInfo, (TCHAR *)PROCINFO_USER_OBJ, DCI_DT_UINT64, DCIDESC_PROCESS_USEROBJ },
217 { _T("Process.UserTime(*)"), H_ProcInfo, (TCHAR *)PROCINFO_UTIME, DCI_DT_UINT64, DCIDESC_PROCESS_USERTIME },
218 { _T("Process.VMSize(*)"), H_ProcInfo, (TCHAR *)PROCINFO_VMSIZE, DCI_DT_UINT64, DCIDESC_PROCESS_VMSIZE },
219 { _T("Process.WkSet(*)"), H_ProcInfo, (TCHAR *)PROCINFO_WKSET, DCI_DT_UINT64, DCIDESC_PROCESS_WKSET },
220 { _T("System.AppAddressSpace"), H_AppAddressSpace, NULL, DCI_DT_UINT, DCIDESC_SYSTEM_APPADDRESSSPACE },
221 { _T("System.ConnectedUsers"), H_ConnectedUsers, NULL, DCI_DT_INT, DCIDESC_SYSTEM_CONNECTEDUSERS },
222
223 { _T("System.CPU.CurrentUsage"), H_CPUUsage, _T("T0U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR },
224 { _T("System.CPU.CurrentUsage.Idle"), H_CPUUsage, _T("T0I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_IDLE },
225 { _T("System.CPU.CurrentUsage.System"), H_CPUUsage, _T("T0s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_SYSTEM },
226 { _T("System.CPU.CurrentUsage.User"), H_CPUUsage, _T("T0u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_USER },
227
228 { _T("System.CPU.CurrentUsage(*)"), H_CPUUsage, _T("C0U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_EX },
229 { _T("System.CPU.CurrentUsage.Idle(*)"), H_CPUUsage, _T("C0I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_IDLE_EX },
230 { _T("System.CPU.CurrentUsage.System(*)"), H_CPUUsage, _T("C0s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_SYSTEM_EX },
231 { _T("System.CPU.CurrentUsage.User(*)"), H_CPUUsage, _T("C0u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGECURR_USER_EX },
232
233 { _T("System.CPU.Usage"), H_CPUUsage, _T("T1U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE },
234 { _T("System.CPU.Usage.Idle"), H_CPUUsage, _T("T1I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_IDLE },
235 { _T("System.CPU.Usage.System"), H_CPUUsage, _T("T1s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_SYSTEM },
236 { _T("System.CPU.Usage.User"), H_CPUUsage, _T("T1u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_USER },
237
238 { _T("System.CPU.Usage(*)"), H_CPUUsage, _T("C1U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_EX },
239 { _T("System.CPU.Usage.Idle(*)"), H_CPUUsage, _T("C1I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_IDLE_EX },
240 { _T("System.CPU.Usage.System(*)"), H_CPUUsage, _T("C1s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_SYSTEM_EX },
241 { _T("System.CPU.Usage.User(*)"), H_CPUUsage, _T("C1u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE_USER_EX },
242
243 { _T("System.CPU.Usage5"), H_CPUUsage, _T("T2U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5 },
244 { _T("System.CPU.Usage5.Idle"), H_CPUUsage, _T("T2I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_IDLE },
245 { _T("System.CPU.Usage5.System"), H_CPUUsage, _T("T2s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_SYSTEM },
246 { _T("System.CPU.Usage5.User"), H_CPUUsage, _T("T2u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_USER },
247
248 { _T("System.CPU.Usage5(*)"), H_CPUUsage, _T("C2U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_EX },
249 { _T("System.CPU.Usage.Idle(*)"), H_CPUUsage, _T("C2I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_IDLE_EX },
250 { _T("System.CPU.Usage.System(*)"), H_CPUUsage, _T("C2s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_SYSTEM_EX },
251 { _T("System.CPU.Usage.User(*)"), H_CPUUsage, _T("C2u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE5_USER_EX },
252
253 { _T("System.CPU.Usage15"), H_CPUUsage, _T("T3U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15 },
254 { _T("System.CPU.Usage5.Idle"), H_CPUUsage, _T("T3I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_IDLE },
255 { _T("System.CPU.Usage5.System"), H_CPUUsage, _T("T3s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_SYSTEM },
256 { _T("System.CPU.Usage5.User"), H_CPUUsage, _T("T3u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_USER },
257
258 { _T("System.CPU.Usage15(*)"), H_CPUUsage, _T("C3U"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_EX },
259 { _T("System.CPU.Usage15.Idle(*)"), H_CPUUsage, _T("C3I"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_IDLE_EX },
260 { _T("System.CPU.Usage15.System(*)"), H_CPUUsage, _T("C3s"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_SYSTEM_EX },
261 { _T("System.CPU.Usage15.User(*)"), H_CPUUsage, _T("C3u"), DCI_DT_FLOAT, DCIDESC_SYSTEM_CPU_USAGE15_USER_EX },
262
263 { _T("System.HandleCount"), H_HandleCount, NULL, DCI_DT_UINT, DCIDESC_SYSTEM_HANDLECOUNT },
264 { _T("System.ProcessCount"), H_ProcCount, NULL, DCI_DT_UINT, DCIDESC_SYSTEM_PROCESSCOUNT },
265 { _T("System.ServiceState(*)"), H_ServiceState, NULL, DCI_DT_INT, DCIDESC_SYSTEM_SERVICESTATE },
266 { _T("System.ThreadCount"), H_ThreadCount, NULL, DCI_DT_UINT, DCIDESC_SYSTEM_THREADCOUNT },
267 { _T("System.Update.LastDetectTime"), H_SysUpdateTime, _T("Detect"), DCI_DT_INT64, _T("System update: last detect time") },
268 { _T("System.Update.LastDownloadTime"), H_SysUpdateTime, _T("Download"), DCI_DT_INT64, _T("System update: last download time") },
269 { _T("System.Update.LastInstallTime"), H_SysUpdateTime, _T("Install"), DCI_DT_INT64, _T("System update: last install time") }
270 };
271
272 /**
273 * Supported lists
274 */
275 static NETXMS_SUBAGENT_LIST m_lists[] =
276 {
277 { _T("Net.ArpCache"), H_ArpCache, NULL },
278 { _T("Net.InterfaceList"), H_InterfaceList, NULL },
279 { _T("Net.InterfaceNames"), H_InterfaceNames, NULL },
280 { _T("Net.IP.RoutingTable"), H_IPRoutingTable, NULL },
281 { _T("System.ActiveUserSessions"), H_ActiveUserSessions, NULL },
282 { _T("System.Desktops(*)"), H_Desktops, NULL },
283 { _T("System.ProcessList"), H_ProcessList, NULL },
284 { _T("System.Services"), H_ServiceList, NULL },
285 { _T("System.WindowStations"), H_WindowStations, NULL }
286 };
287
288 /**
289 * Supported tables
290 */
291 static NETXMS_SUBAGENT_TABLE m_tables[] =
292 {
293 { _T("System.InstalledProducts"), H_InstalledProducts, NULL, _T("NAME"), DCTDESC_SYSTEM_INSTALLED_PRODUCTS },
294 { _T("System.Processes"), H_ProcessTable, NULL, _T("PID"), DCTDESC_SYSTEM_PROCESSES },
295 { _T("System.Services"), H_ServiceTable, NULL, _T("Name"), _T("Services") }
296 };
297
298 /**
299 * Supported actions
300 */
301 static NETXMS_SUBAGENT_ACTION m_actions[] =
302 {
303 { _T("System.Restart"), H_ActionShutdown, _T("R"), _T("Restart system") },
304 { _T("System.Shutdown"), H_ActionShutdown, _T("S"), _T("Shutdown system") },
305 { _T("User.ChangePassword"), H_ChangeUserPassword, NULL, _T("Change password for given user") }
306 };
307
308 /**
309 * Subagent information
310 */
311 static NETXMS_SUBAGENT_INFO m_info =
312 {
313 NETXMS_SUBAGENT_INFO_MAGIC,
314 _T("WinNT"), NETXMS_VERSION_STRING,
315 SubAgentInit, SubAgentShutdown, NULL,
316 sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
317 m_parameters,
318 sizeof(m_lists) / sizeof(NETXMS_SUBAGENT_LIST),
319 m_lists,
320 sizeof(m_tables) / sizeof(NETXMS_SUBAGENT_TABLE),
321 m_tables,
322 sizeof(m_actions) / sizeof(NETXMS_SUBAGENT_ACTION),
323 m_actions,
324 0, NULL // push parameters
325 };
326
327 /**
328 * Entry point for NetXMS agent
329 */
330 DECLARE_SUBAGENT_ENTRY_POINT(WINNT)
331 {
332 *ppInfo = &m_info;
333 ImportSymbols();
334
335 OSVERSIONINFO ver;
336 ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
337 if (GetVersionEx(&ver))
338 {
339 if (ver.dwMajorVersion < 6)
340 g_isWin5 = true;
341 }
342 return TRUE;
343 }
344
345 /**
346 * DLL entry point
347 */
348 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
349 {
350 if (dwReason == DLL_PROCESS_ATTACH)
351 DisableThreadLibraryCalls(hInstance);
352 return TRUE;
353 }