1 #include <WtsApi32.h> 2 #pragma comment(lib, "WtsApi32.lib") 3 void fun17(int argc, char *argv[]){ 4 ////计算机名 5 //TCHAR szServerName[32] = TEXT("DESKTOP-45J0D6P"); 6 ////把这台计算机当服务打开 7 //HANDLE hWtsServer = WTSOpenServer(szServerName); 8 //if (hWtsServer == INVALID_HANDLE_VALUE) { 9 // printf("WTSOpenServer 失败\n"); 10 // return; 11 //} 12 //终端服务进程信息 13 PWTS_PROCESS_INFO pProcessInfo; 14 //进程个数 15 DWORD dwCount; 16 //if (!WTSEnumerateProcesses(hWtsServer, 0, 1, &pProcessInfo, &dwCount)) { 17 if (!WTSEnumerateProcesses(WTS_CURRENT_SERVER_HANDLE, 0, 1, &pProcessInfo, &dwCount)) { 18 printf("WTSEnumerateProcesses 失败\n"); 19 return; 20 } 21 //枚举所有进程的信息 22 for (DWORD i = 0; i < dwCount; ++i) { 23 printf("PID:%d\t名称:%s\n", pProcessInfo[i].ProcessId, pProcessInfo[i].pProcessName); 24 } 25 //内存释放 26 WTSFreeMemory(pProcessInfo); 27 //关闭服务 28 //WTSCloseServer(hWtsServer); 29 }
原文地址:https://www.cnblogs.com/xuqiulin/p/11992723.html
时间: 2024-10-04 12:09:35