Platform SDK: Network Management |
The NetServerDiskEnum function retrieves a list of disk drives on a server. The function returns an array of three-character strings (a drive letter, a colon, and a terminating null character).
Only members of the Administrators or Account Operators local group can successfully execute the NetServerDiskEnum function on a remote computer. No special group membership is required for local calls.
NET_API_STATUS NetServerDiskEnum( LPWSTR servername, DWORD level, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle );
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value can be one of the following error codes.
Value | Meaning |
---|---|
ERROR_ACCESS_DENIED | The user does not have access to the requested information. |
ERROR_INVALID_LEVEL | The value specified for the level parameter is invalid. |
ERROR_MORE_DATA | More entries are available. Specify a large enough buffer to receive all entries. |
ERROR_NOT_ENOUGH_MEMORY | Insufficient memory is available. |
The following code sample demonstrates how to call the NetServerDiskEnum function to retrieve a list of disk drives on a server. The sample calls NetServerDiskEnum, specifying the information level 0 (required). If there are entries to return, and the user has access to the information, it prints a list of the drives, in the format of a three-character string: a drive letter, a colon, and a terminating null character. The sample also prints the total number of entries that are available and the number of entries actually enumerated. Finally, the code sample frees the memory allocated for the buffer.
#ifndef UNICODE #define UNICODE #endif #include <stdio.h> #include <assert.h> #include <windows.h> #include <lm.h> int wmain(int argc, wchar_t *argv[]) { const int ENTRY_SIZE = 3; // Drive letter, colon, NULL LPTSTR pBuf = NULL; DWORD dwLevel = 0; // level must be zero DWORD dwPrefMaxLen = -1; DWORD dwEntriesRead = 0; DWORD dwTotalEntries = 0; 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 NetServerDiskEnum function. // nStatus = NetServerDiskEnum(pszServerName, dwLevel, (LPBYTE *) &pBuf, dwPrefMaxLen, &dwEntriesRead, &dwTotalEntries, NULL); // // If the call succeeds, // if (nStatus == NERR_Success) { LPTSTR pTmpBuf; if ((pTmpBuf = pBuf) != NULL) { DWORD i; DWORD dwTotalCount = 0; // // Loop through the entries. // for (i = 0; i < dwEntriesRead; i++) { assert(pTmpBuf != NULL); if (pTmpBuf == NULL) { // On a remote computer, only members of the // Administrators or the Account Operators // local group can execute NetServerDiskEnum. // fprintf(stderr, "An access violation has occurred\n"); break; } // // Print drive letter, colon, NULL for each drive; // the number of entries actually enumerated; and // the total number of entries available. // fwprintf(stdout, L"\tDisk: %S\n", pTmpBuf); pTmpBuf += ENTRY_SIZE; dwTotalCount++; } fprintf(stderr, "\nEntries enumerated: %d\n", dwTotalCount); } } else fprintf(stderr, "A system error has occurred: %d\n", nStatus); // // Free the allocated buffer. // if (pBuf != NULL) NetApiBufferFree(pBuf); return 0; }
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management server functions. For more information, see IADsComputer.
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Unsupported.
Header: Declared in Lmserver.h; include Lm.h.
Library: Use Netapi32.lib.
Network Management Overview, Network Management Functions, Server Functions, NetServerEnum