18,356
社区成员
发帖
与我相关
我的任务
分享
#ifndef UNICODE
#define UNICODE
#endif
#include <stdio.h>
#include <windows.h>
#include <lm.h>
int wmain(int argc, wchar_t *argv[])
{
LPTIME_OF_DAY_INFO pBuf = NULL;
NET_API_STATUS nStatus;
LPTSTR pszServerName = NULL;
if (argc > 2)
{
fwprintf(stderr, L"Usage: %s [\\\\ServerName]\n", argv[0]);
exit(1);
}
// The server is not the default local computer.
//
if (argc == 2)
pszServerName = argv[1];
//
// Call the NetRemoteTOD function.
//
nStatus = NetRemoteTOD(pszServerName,
(LPBYTE *)&pBuf);
//
// If the function succeeds, display the current date and time.
//
if (nStatus == NERR_Success)
{
if (pBuf != NULL)
{
fprintf(stderr, "\nThe current date is: %d/%d/%d\n",
pBuf->tod_month, pBuf->tod_day, pBuf->tod_year);
fprintf(stderr, "The current time is: %d:%d:%d\n",
pBuf->tod_hours, pBuf->tod_mins, pBuf->tod_secs);
}
}
//
// Otherwise, display a system error.
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
return 0;
}