什么网络监视器?查看谁链接到你的机器吗?MSDN里有例子。
解决方案 »
- CListBox ASSERT(IsWindow()) 断言失败
- 用sdk实现一个小功能,请高手帮个忙(不要用mfc语句)
- 怎样解决内存泄漏的问题?
- 关于用CFileDialog对话框获取文件名的问题
- 嵌入网页的ActiveX 如何得到IHTMLDocument2
- 重庆某家公司的面试题,无聊的朋友进来看看!
- *高分醒目*usbioctl.h中的IOCTL_USB_HCD_DISABLE_PORT
- ======我想把update合并到select语句中去,可以做到吗?在线等=========
- 一个资源,有一个线程专门写入数据,有两个线程专门读出数据.这种情况怎么安排,效率比较高?
- 请问谁有关于CTreeView的使用的简单例子
- 请那位大侠讲一下 fatal error C1010: unexpected end of file while looking for precompiled header directive 的产生原因和解决方法!
- 关于多线程的问题,请高手指导!
#define UNICODE
#endif#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <lm.h>int wmain(int argc, wchar_t *argv[])
{
LPSESSION_INFO_10 pBuf = NULL;
LPSESSION_INFO_10 pTmpBuf;
DWORD dwLevel = 10;
DWORD dwPrefMaxLen = -1;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD i;
DWORD dwTotalCount = 0;
LPTSTR pszServerName = NULL;
LPTSTR pszClientName = NULL;
LPTSTR pszUserName = NULL;
NET_API_STATUS nStatus;
//
// Check command line arguments.
//
if (argc > 4)
{
wprintf(L"Usage: %s [\\\\ServerName] [\\\\ClientName] [UserName]\n", argv[0]);
exit(1);
} if (argc >= 2)
pszServerName = argv[1]; if (argc >= 3)
pszClientName = argv[2]; if (argc == 4)
pszUserName = argv[3];
//
// Call the NetSessionEnum function, specifying level 10.
//
do // begin do
{
nStatus = NetSessionEnum(pszServerName,
pszClientName,
pszUserName,
dwLevel,
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries.
//
for (i = 0; (i < dwEntriesRead); i++)
{
assert(pTmpBuf != NULL); if (pTmpBuf == NULL)
{
fprintf(stderr, "An access violation has occurred\n");
break;
}
//
// Print the retrieved data.
//
wprintf(L"\n\tClient: %s\n", pTmpBuf->sesi10_cname);
wprintf(L"\tUser: %s\n", pTmpBuf->sesi10_username);
printf("\tActive: %d\n", pTmpBuf->sesi10_time);
printf("\tIdle: %d\n", pTmpBuf->sesi10_idle_time); pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, indicate a system error.
//
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Free the allocated memory.
//
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
//
// Continue to call NetSessionEnum while
// there are more entries.
//
while (nStatus == ERROR_MORE_DATA); // end do // Check again for an allocated buffer.
//
if (pBuf != NULL)
NetApiBufferFree(pBuf);
//
// Print the final count of sessions enumerated.
//
fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount); return 0;
}
#include <assert.h>
#include <windows.h>
#include <svrapi.h>const short MAX_ENTRIES = 20;int main(int argc, char FAR * argv[])
{
char FAR * pszServerName = NULL;
short nLevel = 50;
struct session_info_50* pBuf = NULL;
struct session_info_50* pTmpBuf = NULL;
short cbBuffer;
short nEntriesRead = 0;
short nTotalEntries = 0;
short nTotalCount = 0;
int i;
NET_API_STATUS nStatus;
//
// ServerName can be NULL to indicate the local computer.
//
if (argc > 2)
{
printf("Usage: %s [\\\\ServerName]\n", argv[0]);
exit(1);
} if (argc == 2)
pszServerName = argv[1]; cbBuffer = MAX_ENTRIES * sizeof(struct session_info_50);
//
// Allocate the memory required to receive a maximum of
// 20 session_info_50 structures.
//
pBuf = malloc(cbBuffer); if (pBuf == NULL)
printf("No memory\n"); // Call the NetSessionEnum function to list the
// sessions, specifying information level 50.
//
nStatus = NetSessionEnum(pszServerName,
nLevel,
(char FAR *)pBuf,
cbBuffer,
&nEntriesRead,
&nTotalEntries);
//
// Loop through the entries; process errors.
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
for (i = 0; (i < nEntriesRead); i++)
{
assert(pTmpBuf != NULL); if (pTmpBuf == NULL)
{
fprintf(stderr, "An access violation has occurred\n");
break;
}
//
// Display the information for each entry retrieved.
//
printf("\n\tClient: %s\n", pTmpBuf->sesi50_cname);
printf("\tUser: %s\n", pTmpBuf->sesi50_username);
printf("\tActive: %d\n", pTmpBuf->sesi50_time);
printf("\tIdle: %d\n", pTmpBuf->sesi50_idle_time);
printf("\tKey: %d\n", pTmpBuf->sesi50_key); pTmpBuf++;
nTotalCount++;
}
}
}
else
fprintf(stderr, "A system error has occurred: %d\n", nStatus);
//
// Display a warning if the buffer was not large enough
// to contain all available entries.
//
if ((nEntriesRead < nTotalEntries) || (nStatus == ERROR_MORE_DATA))
fprintf(stderr, "Not all entries have been enumerated\n");
//
// Free the allocated memory.
//
if (pBuf != NULL)
free(pBuf); fprintf(stderr, "\nTotal of %d entries enumerated\n", nTotalCount); return 0;
}
http://nowcan.yeah.net