Windows 2000用のWTSEnumerateProcessesA コード
_declspec(dllexport) int WINAPI WTSEnumerateProcessesA(HANDLE hServer, DWORD p1, DWORD p2, PWTS_PROCESS_INFO *ProcessInfo, DWORD *cb){ int result = WTSEnumerateProcessesA(hServer,p1,p2,ProcessInfo,cb); if(hServer == WTS_CURRENT_SERVER_HANDLE &&*cb == 0){ HLOCAL hL; int i,j; DWORD *Prc = NULL; char *p; Prc = (DWORD*)LocalAlloc(0x40,0x2000); *cb=0x2000; EnumProcesses(Prc,*cb,cb); *cb>>=2; j=(*cb)*sizeof(WTS_PROCESS_INFO); *ProcessInfo= (PWTS_PROCESS_INFO)LocalAlloc(0x40,j+256); p=(char*)*ProcessInfo+j; for(i=0;i<(int)*cb;i++){ int r=ProcessIdToSessionId(Prc[i],&(*ProcessInfo)[i].SessionId); (*ProcessInfo)[i].ProcessId=Prc[i]; (*ProcessInfo)[i].pProcessName=p; (*ProcessInfo)[i].pUserSid=NULL; HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, (*ProcessInfo)[i].ProcessId ); if( NULL != hProcess ) { int l; *p=0; GetModuleBaseName(hProcess,NULL ,p,256); l=lstrlen(p); if(l){ j+=((l+4)>>2)<<2; p=(char*)*ProcessInfo+j; } if(i+1<(int)*cb) { hL=LocalReAlloc((HLOCAL)*ProcessInfo, j+256,0x40); if(hL) *ProcessInfo=(PWTS_PROCESS_INFO)hL; } CloseHandle(hProcess); } } result=1; } return result; } |
一部のアプリが、TerminalServiceのこの関数を参照しているときいたので、実装用のコードを書いてみた
WTSAPI32.DLLのラッパーになる予定です。
Comments