#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; }//这是MSDN的代码,可以运行。 Project->Settings->Link页的Object/library modules里边添加:Netapi32.lib 就可以了
TIME_OF_DAY_INFO* pt;
BYTE* p=new BYTE[sizeof(TIME_OF_DAY_INFO)];
if(NERR_Success==NetRemoteTOD(0,&p))//参数0表示本机
pt=(TIME_OF_DAY_INFO*)p;//调用成功
...//可以看看pt的值了
NetApiBufferFree(pt);//释放
#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;
}//这是MSDN的代码,可以运行。
Project->Settings->Link页的Object/library modules里边添加:Netapi32.lib
就可以了