using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class NetApi32 { /// public const string SERVICE_SERVER = "LanmanServer"; /// public const string SERVICE_WORKSTATION = "LanmanWorkstation"; /// Retrieves operating statistics for a service. Currently, only the workstation and server services are supported. /// /// Pointer to a string that specifies the DNS or NetBIOS name of the server on which the function is to execute. If this parameter /// is NULL, the local computer is used. /// /// /// Pointer to a string that specifies the name of the service about which to get the statistics. Only the values /// SERVICE_SERVER and SERVICE_WORKSTATION are currently allowed. /// /// /// Specifies the information level of the data. This parameter can be the following value. /// /// /// Value /// Meaning /// /// /// 0 /// /// Return statistics about a workstation or a server. The bufptr parameter points to a STAT_WORKSTATION_0 or a STAT_SERVER_0 structure. /// /// /// /// /// This parameter must be zero. /// /// Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer /// is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management /// Function Buffers and Network Management Function Buffer Lengths. /// /// /// If the function succeeds, the return value is NERR_Success. /// If the function fails, the return value is a system error code. For a list of error codes, see System Error Codes. /// /// /// No special group membership is required to obtain workstation statistics. Only members of the Administrators or Server Operators /// local group can successfully execute the NetStatisticsGet function on a remote server. /// // https://docs.microsoft.com/en-us/windows/desktop/api/lmstats/nf-lmstats-netstatisticsget NET_API_STATUS NET_API_FUNCTION // NetStatisticsGet( LPTSTR ServerName, LPTSTR Service, DWORD Level, DWORD Options, LPBYTE *Buffer ); [DllImport(Lib.NetApi32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("lmstats.h", MSDNShortId = "d0e51d8a-2f54-42ca-9759-0da82c1f0f55")] public static extern Win32Error NetStatisticsGet([Optional] string ServerName, string Service, uint Level, [Optional] uint Options, out SafeNetApiBuffer Buffer); /// /// Contains statistical information about the server. /// // https://docs.microsoft.com/en-us/windows/desktop/api/lmstats/ns-lmstats-_stat_server_0 typedef struct _STAT_SERVER_0 { DWORD // sts0_start; DWORD sts0_fopens; DWORD sts0_devopens; DWORD sts0_jobsqueued; DWORD sts0_sopens; DWORD sts0_stimedout; DWORD // sts0_serrorout; DWORD sts0_pwerrors; DWORD sts0_permerrors; DWORD sts0_syserrors; DWORD sts0_bytessent_low; DWORD // sts0_bytessent_high; DWORD sts0_bytesrcvd_low; DWORD sts0_bytesrcvd_high; DWORD sts0_avresponse; DWORD sts0_reqbufneed; DWORD // sts0_bigbufneed; } STAT_SERVER_0, *PSTAT_SERVER_0, *LPSTAT_SERVER_0; [PInvokeData("lmstats.h", MSDNShortId = "7eb4e4a9-f4db-4702-a4ad-2d8bfac9f9ce")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct STAT_SERVER_0 { /// /// /// Specifies a DWORD value that indicates the time when statistics collection started (or when the statistics were last /// cleared). The value is stored as the number of seconds that have elapsed since 00:00:00, January 1, 1970, GMT. To calculate /// the length of time that statistics have been collected, subtract the value of this member from the present time. /// /// public uint sts0_start; /// /// /// Specifies a DWORD value that indicates the number of times a file is opened on a server. This includes the number of times /// named pipes are opened. /// /// public uint sts0_fopens; /// /// Specifies a DWORD value that indicates the number of times a server device is opened. /// public uint sts0_devopens; /// /// Specifies a DWORD value that indicates the number of server print jobs spooled. /// public uint sts0_jobsqueued; /// /// Specifies a DWORD value that indicates the number of times the server session started. /// public uint sts0_sopens; /// /// Specifies a DWORD value that indicates the number of times the server session automatically disconnected. /// public uint sts0_stimedout; /// /// Specifies a DWORD value that indicates the number of times the server sessions failed with an error. /// public uint sts0_serrorout; /// /// Specifies a DWORD value that indicates the number of server password violations. /// public uint sts0_pwerrors; /// /// Specifies a DWORD value that indicates the number of server access permission errors. /// public uint sts0_permerrors; /// /// Specifies a DWORD value that indicates the number of server system errors. /// public uint sts0_syserrors; /// /// Specifies the low-order DWORD of the number of server bytes sent to the network. /// public uint sts0_bytessent_low; /// /// Specifies the high-order DWORD of the number of server bytes sent to the network. /// public uint sts0_bytessent_high; /// /// Specifies the low-order DWORD of the number of server bytes received from the network. /// public uint sts0_bytesrcvd_low; /// /// Specifies the high-order DWORD of the number of server bytes received from the network. /// public uint sts0_bytesrcvd_high; /// /// Specifies a DWORD value that indicates the average server response time (in milliseconds). /// public uint sts0_avresponse; /// /// /// Specifies a DWORD value that indicates the number of times the server required a request buffer but failed to allocate one. /// This value indicates that the server parameters may need adjustment. /// /// public uint sts0_reqbufneed; /// /// /// Specifies a DWORD value that indicates the number of times the server required a big buffer but failed to allocate one. This /// value indicates that the server parameters may need adjustment. /// /// public uint sts0_bigbufneed; } /// Contains statistical information about the specified workstation. // https://docs.microsoft.com/en-us/windows/win32/api/lmstats/ns-lmstats-stat_workstation_0~r1 typedef struct _STAT_WORKSTATION_0 { // LARGE_INTEGER StatisticsStartTime; LARGE_INTEGER BytesReceived; LARGE_INTEGER SmbsReceived; LARGE_INTEGER // PagingReadBytesRequested; LARGE_INTEGER NonPagingReadBytesRequested; LARGE_INTEGER CacheReadBytesRequested; LARGE_INTEGER // NetworkReadBytesRequested; LARGE_INTEGER BytesTransmitted; LARGE_INTEGER SmbsTransmitted; LARGE_INTEGER // PagingWriteBytesRequested; LARGE_INTEGER NonPagingWriteBytesRequested; LARGE_INTEGER CacheWriteBytesRequested; LARGE_INTEGER // NetworkWriteBytesRequested; DWORD InitiallyFailedOperations; DWORD FailedCompletionOperations; DWORD ReadOperations; DWORD // RandomReadOperations; DWORD ReadSmbs; DWORD LargeReadSmbs; DWORD SmallReadSmbs; DWORD WriteOperations; DWORD // RandomWriteOperations; DWORD WriteSmbs; DWORD LargeWriteSmbs; DWORD SmallWriteSmbs; DWORD RawReadsDenied; DWORD RawWritesDenied; // DWORD NetworkErrors; DWORD Sessions; DWORD FailedSessions; DWORD Reconnects; DWORD CoreConnects; DWORD Lanman20Connects; DWORD // Lanman21Connects; DWORD LanmanNtConnects; DWORD ServerDisconnects; DWORD HungSessions; DWORD UseCount; DWORD FailedUseCount; // DWORD CurrentCommands; } STAT_WORKSTATION_0, *PSTAT_WORKSTATION_0, *LPSTAT_WORKSTATION_0; [PInvokeData("lmstats.h")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct STAT_WORKSTATION_0 { /// /// Specifies the time statistics collection started. This member also indicates when statistics for the workstations were last /// cleared. The value is stored as the number of seconds elapsed since 00:00:00, January 1, 1970. /// public long StatisticsStartTime; /// Specifies the total number of bytes received by the workstation. public long BytesReceived; /// Specifies the total number of server message blocks (SMBs) received by the workstation. public long SmbsReceived; /// Specifies the total number of bytes that have been read by paging I/O requests. public long PagingReadBytesRequested; /// Specifies the total number of bytes that have been read by non-paging I/O requests. public long NonPagingReadBytesRequested; /// Specifies the total number of bytes that have been read by cache I/O requests. public long CacheReadBytesRequested; /// Specifies the total amount of bytes that have been read by disk I/O requests. public long NetworkReadBytesRequested; /// Specifies the total number of bytes transmitted by the workstation. public long BytesTransmitted; /// Specifies the total number of SMBs transmitted by the workstation. public long SmbsTransmitted; /// Specifies the total number of bytes that have been written by paging I/O requests. public long PagingWriteBytesRequested; /// Specifies the total number of bytes that have been written by non-paging I/O requests. public long NonPagingWriteBytesRequested; /// Specifies the total number of bytes that have been written by cache I/O requests. public long CacheWriteBytesRequested; /// Specifies the total number of bytes that have been written by disk I/O requests. public long NetworkWriteBytesRequested; /// Specifies the total number of network operations that failed to begin. public uint InitiallyFailedOperations; /// Specifies the total number of network operations that failed to complete. public uint FailedCompletionOperations; /// Specifies the total number of read operations initiated by the workstation. public uint ReadOperations; /// Specifies the total number of random access reads initiated by the workstation. public uint RandomReadOperations; /// Specifies the total number of read requests the workstation has sent to servers. public uint ReadSmbs; /// /// Specifies the total number of read requests the workstation has sent to servers that are greater than twice the size of the /// server's negotiated buffer size. /// public uint LargeReadSmbs; /// /// Specifies the total number of read requests the workstation has sent to servers that are less than 1/4 of the size of the /// server's negotiated buffer size. /// public uint SmallReadSmbs; /// Specifies the total number of write operations initiated by the workstation. public uint WriteOperations; /// Specifies the total number of random access writes initiated by the workstation. public uint RandomWriteOperations; /// public uint WriteSmbs; /// /// Specifies the total number of write requests the workstation has sent to servers that are greater than twice the size of the /// server's negotiated buffer size. /// public uint LargeWriteSmbs; /// /// Specifies the total number of write requests the workstation has sent to servers that are less than 1/4 of the size of the /// server's negotiated buffer size. /// public uint SmallWriteSmbs; /// public uint RawReadsDenied; /// Specifies the total number of raw write requests made by the workstation that have been denied. public uint RawWritesDenied; /// Specifies the total number of network errors received by the workstation. public uint NetworkErrors; /// public uint Sessions; /// Specifies the number of times the workstation attempted to create a session but failed. public uint FailedSessions; /// Specifies the total number of connections that have failed. public uint Reconnects; /// Specifies the total number of connections to servers supporting the PCNET dialect that have succeeded. public uint CoreConnects; /// Specifies the total number of connections to servers supporting the LanManager 2.0 dialect that have succeeded. public uint Lanman20Connects; /// Specifies the total number of connections to servers supporting the LanManager 2.1 dialect that have succeeded. public uint Lanman21Connects; /// Specifies the total number of connections to servers supporting the NTLM dialect that have succeeded. public uint LanmanNtConnects; /// Specifies the number of times the workstation was disconnected by a network server. public uint ServerDisconnects; /// Specifies the total number of sessions that have expired on the workstation. public uint HungSessions; /// Specifies the total number of network connections established by the workstation. public uint UseCount; /// Specifies the total number of failed network connections for the workstation. public uint FailedUseCount; /// Specifies the number of current requests that have not been completed. public uint CurrentCommands; } } }