如何枚举当计算机的所有网络连接名,以及其状态???????????????
比如在WIN2K的下有两个网络连接,"本地连接"与"拨号连接",如何通过程序枚举这两个的连接的状态
比如在WIN2K的下有两个网络连接,"本地连接"与"拨号连接",如何通过程序枚举这两个的连接的状态
解决方案 »
- 怎样让MFC对话框里的编辑框控件的滚动条始终位于底部?
- 请教matlab里面方差计算问题?
- 谁能给我提供一个进货管理子系统的源码啊
- 处未处理的异常: 0xC0000005 帮忙看看
- 垂直滚动条spin的小问题!
- 为什么按钮用 GetWindowRect 得到的 RECT 和刚 MoveWindow 时用到的 RECT 不一样?
- 求助--vc程序界面的优化开发
- windows编程,小游戏
- 请问键盘全局钩子使用底层钩子,WH_KEYBOARD_LL,win7运行会卡住
- ReceiveFrom接收时出现 描述符不是一个套接字该怎么解决?
- 请问到哪能弄到Microsofe DataGrid Control这个ActivX控件呀?
- VC的安装问题
----------------
#ifndef UNICODE
#define UNICODE
#endif#include <stdio.h>
#include <assert.h>
#include <windows.h>
#include <lm.h>
#pragma comment(lib,"Netapi32.lib")int wmain(int argc, wchar_t *argv[])
{
LPSESSION_INFO_10 pBuf = NULL;
LPSESSION_INFO_10 pTmpBuf;
DWORD dwLevel = 10;
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
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;
}