列举当前登陆的用户
来源:互联网 发布:微信单删软件 编辑:程序博客网 时间:2024/06/14 12:00
int main(argc, argv) int argc; char *argv[];{ LPWKSTA_USER_INFO_0 /* * This structure contains the name of the user on a specified workstation. */ buffer = NULL, tempbuffer = NULL; NET_API_STATUS /* * Return code Description * NERR_SUCCESS The function call successfull. * ERROR_ACCESS_DENIED The user does not have access to the requested information. * ERROR_MORE_DATA More totalentries are available. Specify a large enough * buffer to receive all totalentries. * ERROR_INVALID_LEVEL The level parameter is invalid. */ status; char /* * Pointer to a string that specifies the DNS or NetBIOS name of the remote server on * which the function is to execute. If this parameter is NULL, the local computer is used. */ *server = NULL, username[MAX_PATH], servername[MAX_PATH * 2]; DWORD /* * Value Meaning * 0 Return the names of users currently logged on to the workstation. * The bufptr parameter points to an array of WKSTA_USER_INFO_0 structures. * 1 Return the names of the current users and the domains accessed by the workstation. * The bufptr parameter points to an array of WKSTA_USER_INFO_1 structures. */ level = 0, /* * Specifies the preferred maximum length of returned data, in bytes. * If you specify MAX_PREFERRED_LENGTH, the function allocates the amount of memory * required for the data. If you specify another value in this parameter, * it can restrict the number of bytes that the function returns. * If the buffer size is insufficient to hold all entries, * the function returns ERROR_MORE_DATA. For more information */ prefmaxlen = MAX_PREFERRED_LENGTH, /* * Pointer to a value that receives the count of elements actually enumerated. */ entriesread = 0, /* * Pointer to a value that receives the total number of entries that could have been * enumerated from the current resume position. Note that applications should consider * this value only as a hint. */ totalentries = 0, /* * Pointer to a value that contains a resume handle which is used to continue an * existing search. The handle should be zero on the first call and left unchanged * for subsequent calls. If this parameter is NULL, no resume handle is stored. */ resumehandles = 0, usercount = 0, i, j; if (argc > 2) { fprintf(stderr, "Usage: %s [\\\\ServerName]\n", argv[0]); return 1; } fprintf(stdout, "\nLogged users on "); /* * The server is not default of local computer. */ if (argc != 2) { server = NULL; fprintf(stdout, "localhost:\n"); } else { // The first parameter of the NetWkstaUserEnum function must be unicode format. MultiByteToWideChar( 0, 0, argv[1], lstrlen(argv[1]), (LPWSTR)servername, MAX_PATH); server = servername; fprintf(stdout, "%s:\n", argv[1]); } do { /* * Call the NetWkstaUserEnum function, specifying level 0. * * 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. */ status = NetWkstaUserEnum( (LPWSTR)server, level, (LPBYTE*)&buffer, prefmaxlen, &entriesread, &totalentries, &resumehandles); // If an error has occurred, if (status != NERR_SUCCESS) if (status != ERROR_MORE_DATA) { fprintf(stderr, "A system error has occurred: %d\n", status); break; } // If the call succeeds, if ((tempbuffer = buffer) != NULL) { for (i = 0; i < entriesread; i++) { if (tempbuffer == NULL) { /* * Only members of the Administrators local group * can successfully execute NetWkstaUserEnum * locally and on a remote server. */ fprintf(stderr, "An access violation has occurred\n"); break; } for (j = 0; ; j++) if (!tempbuffer->wkui0_username[j]) break; // Emptying the username. RtlZeroMemory(username, MAX_PATH); WideCharToMultiByte( 0, 0, tempbuffer->wkui0_username, j + 1, username, MAX_PATH, 0, 0); // Print the user logged on to the workstation. fprintf(stdout, " %d -- %s\n", usercount + 1, username); tempbuffer++; usercount++; } // Free the allocated memory. NetApiBufferFree(buffer); buffer = NULL; } } /* * Continue to call NetWkstaUserEnum while * there are more totalentries. */ while (status == ERROR_MORE_DATA); // end do fprintf(stdout, "\n\tTotal %lu users.\n", usercount); // Check again for allocated memory. if (buffer != NULL) NetApiBufferFree(buffer); return 0;}
- 列举当前登陆的用户
- Oracle查看当前登陆的用户
- mysq显示当前登陆的用户
- 列举当前所有的进程
- 列举当前连接的会话
- 检查当前用户是否登陆
- 列举当前运行的所有进程
- VC列举当前电脑存在的设备
- ORACEL查看当前登陆用户的权限或者角色
- Oracle查看当前登陆用户的权限或者角色
- Oracle查看当前登陆用户的权限或者角色
- Oracle查看当前登陆用户的权限或者角色
- TortoiseSVN清除当前登陆用户 切换用户
- MySQL入门--查看当前的mysql客户端版本号、当前系统时间、登陆的用户
- MySQL入门--查看当前的mysql客户端版本号、当前系统时间、登陆的用户
- 如何查看用户当前shell和修改用户登陆时的默认shell
- TOP中得到当前登陆用户
- PHP获取当前登陆用户IP
- 在路上
- sqlite api
- 常用原理图器件符号和练习用图
- Compressed sensing 压缩感知/压缩传感 入门介绍
- PCB常见封装形式
- 列举当前登陆的用户
- linux下C语言多线程(五)杂项函数
- 易语言取外网ip的两种方法
- 列举当前连接的会话
- 接到腾讯的电话
- 从头到尾彻底理解傅里叶变换算法
- Oracle超出最大连接数问题及解决
- socket简单通信编程 发送字符串
- 读书笔记目录