[SRVSVC][WKSSVC][NET] Improve server and workstation statistics

- Server and Workstation services return proper boot time.
- Net formats boot time properly.

CORE-19198
This commit is contained in:
Eric Kohl
2025-11-09 15:22:32 +01:00
parent 318a040ccf
commit bb7a6134c4
5 changed files with 68 additions and 31 deletions
+31 -29
View File
@@ -18,7 +18,7 @@ DisplayServerStatistics(VOID)
LARGE_INTEGER LargeValue;
FILETIME FileTime, LocalFileTime;
SYSTEMTIME SystemTime;
WORD wHour;
WCHAR DateBuffer[32], TimeBuffer[32];
INT nPaddedLength = 35;
NET_API_STATUS Status;
@@ -44,21 +44,22 @@ DisplayServerStatistics(VOID)
FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
FileTimeToSystemTime(&LocalFileTime, &SystemTime);
wHour = SystemTime.wHour;
if (wHour == 0)
{
wHour = 12;
}
else if (wHour > 12)
{
wHour = wHour - 12;
}
GetDateFormatW(LOCALE_USER_DEFAULT,
DATE_SHORTDATE,
&SystemTime,
NULL,
DateBuffer,
ARRAYSIZE(DateBuffer));
GetTimeFormatW(LOCALE_USER_DEFAULT,
0,
&SystemTime,
NULL,
TimeBuffer,
ARRAYSIZE(TimeBuffer));
PrintMessageString(4600);
ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n",
SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,
wHour, SystemTime.wMinute,
(SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM");
ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer);
PrintPaddedMessageString(4601, nPaddedLength);
ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens);
@@ -131,7 +132,7 @@ DisplayWorkstationStatistics(VOID)
LARGE_INTEGER LargeValue;
FILETIME FileTime, LocalFileTime;
SYSTEMTIME SystemTime;
WORD wHour;
WCHAR DateBuffer[32], TimeBuffer[32];
INT nPaddedLength = 47;
NET_API_STATUS Status;
@@ -142,7 +143,7 @@ DisplayWorkstationStatistics(VOID)
goto done;
Status = NetStatisticsGet(NULL,
SERVICE_SERVER,
SERVICE_WORKSTATION,
0,
0,
(LPBYTE*)&StatisticsInfo);
@@ -159,21 +160,22 @@ DisplayWorkstationStatistics(VOID)
FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
FileTimeToSystemTime(&LocalFileTime, &SystemTime);
wHour = SystemTime.wHour;
if (wHour == 0)
{
wHour = 12;
}
else if (wHour > 12)
{
wHour = wHour - 12;
}
GetDateFormatW(LOCALE_USER_DEFAULT,
DATE_SHORTDATE,
&SystemTime,
NULL,
DateBuffer,
ARRAYSIZE(DateBuffer));
GetTimeFormatW(LOCALE_USER_DEFAULT,
0,
&SystemTime,
NULL,
TimeBuffer,
ARRAYSIZE(TimeBuffer));
PrintMessageString(4600);
ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n",
SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,
wHour, SystemTime.wMinute,
(SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM");
ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer);
PrintPaddedMessageString(4630, nPaddedLength);
ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart);
+1
View File
@@ -10,6 +10,7 @@
#include <winreg.h>
#include <winsvc.h>
#include <lmserver.h>
#include <ndk/exfuncs.h>
#include <srvsvc_s.h>
+17 -1
View File
@@ -476,7 +476,9 @@ NetrServerStatisticsGet(
DWORD Options,
LPSTAT_SERVER_0 *InfoStruct)
{
PSTAT_SERVER_0 pStatBuffer;
SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo;
PSTAT_SERVER_0 pStatBuffer = NULL;
NTSTATUS Status;
TRACE("NetrServerStatisticsGet(%p %p %lu 0x%lx %p)\n",
ServerName, Service, Level, Options, InfoStruct);
@@ -493,6 +495,20 @@ NetrServerStatisticsGet(
ZeroMemory(pStatBuffer, sizeof(STAT_SERVER_0));
/* Query the boot time */
Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
&TimeOfDayInfo,
sizeof(TimeOfDayInfo),
NULL);
if (NT_SUCCESS(Status))
{
ULONG Seconds = 0;
if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds))
{
pStatBuffer->sts0_start = Seconds;
}
}
// FIXME: Return the actual statistcs data!
*InfoStruct = pStatBuffer;
+1
View File
@@ -17,6 +17,7 @@
#include <ntsecapi.h>
#include <ntmsv1_0.h>
//#include <ntstatus.h>
#include <ndk/exfuncs.h>
#include <ndk/obfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/rtlfuncs.h>
+18 -1
View File
@@ -1012,7 +1012,9 @@ NetrWorkstationStatisticsGet(
unsigned long Options,
LPSTAT_WORKSTATION_0 *Buffer)
{
PSTAT_WORKSTATION_0 pStatBuffer;
SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo;
PSTAT_WORKSTATION_0 pStatBuffer = NULL;
NTSTATUS Status;
TRACE("NetrWorkstationStatisticsGet(%p %p %lu 0x%lx %p)\n",
ServerName, ServiceName, Level, Options, Buffer);
@@ -1029,6 +1031,21 @@ NetrWorkstationStatisticsGet(
ZeroMemory(pStatBuffer, sizeof(STAT_WORKSTATION_0));
/* Query the boot time */
Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
&TimeOfDayInfo,
sizeof(TimeOfDayInfo),
NULL);
if (NT_SUCCESS(Status))
{
ULONG Seconds = 0;
if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds))
{
pStatBuffer->StatisticsStartTime.u.HighPart = 0;
pStatBuffer->StatisticsStartTime.u.LowPart = Seconds;
}
}
// FIXME: Return the actual statistcs data!
*Buffer = pStatBuffer;