Condividi tramite


Funzione NetRemoteTOD (lmremutl.h)

La funzione NetRemoteTOD restituisce l'ora delle informazioni del giorno da un server specificato.

Sintassi

NET_API_STATUS NET_API_FUNCTION NetRemoteTOD(
  [in]  LPCWSTR UncServerName,
  [out] LPBYTE  *BufferPtr
);

Parametri

[in] UncServerName

Puntatore a una stringa costante che specifica il nome DNS o NetBIOS del server remoto in cui eseguire la funzione. Se questo parametro è NULL, viene usato il computer locale.

[out] BufferPtr

Puntatore all'indirizzo che riceve la struttura di informazioni TIME_OF_DAY_INFO . Questo buffer viene allocato dal sistema e deve essere liberato usando la funzione NetApiBufferFree .

Valore restituito

Se la funzione ha esito positivo, il valore restituito è NERR_Success.

Se la funzione ha esito negativo, il valore restituito è un codice di errore di sistema. Per un elenco di codici di errore, vedere Codici di errore di sistema.

Commenti

Non è necessaria alcuna appartenenza a gruppi speciali per eseguire correttamente la funzione NetRemoteTOD .

Esempio

L'esempio di codice seguente illustra come recuperare e stampare la data e l'ora correnti con una chiamata alla funzione NetRemoteTOD . A tale scopo, l'esempio usa la struttura TIME_OF_DAY_INFO . Infine, l'esempio libera la memoria allocata per il buffer delle informazioni.

#include <stdio.h>
#include <windows.h> 
#include <lm.h>
#pragma comment(lib, "netapi32.lib")

#ifndef UNICODE
#define UNICODE
#endif

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 = (LPTSTR) argv[1];
   //
   // Call the NetRemoteTOD function.
   //
   nStatus = NetRemoteTOD((LPCWSTR) 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;
}

Requisiti

   
Client minimo supportato Windows 2000 Professional [solo app desktop]
Server minimo supportato Windows 2000 Server [solo app desktop]
Piattaforma di destinazione Windows
Intestazione lmremutl.h (include Lm.h)
Libreria Netapi32.lib
DLL Netapi32.dll

Vedi anche

Funzioni di gestione della rete

Panoramica sulla gestione della rete

Funzioni di utilità remota

TIME_OF_DAY_INFO