请教:在windows下如何获得一个进程或服务的状态(如正在运行,没有响应,睡眠等)

abraham6057 2003-12-23 03:45:19
这些在linux下很容易得到的信息为什么在windows下如此难以得到
...全文
29 点赞 收藏 1
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
nscboy 2003-12-24
#ifndef APPLICATION_H
#define APPLICATION_H
#define _DEBUG 1
#include <string.h>
#include <Rpc.h>

BOOL __stdcall EnumWindowProc(HWND, LPARAM);
DWORD dwTotal;

BOOL Application()
{
HDESK hDesk;
LPTSTR lpszDesktop="Default";
//////////////////////////////////////////
DWORD dwThreadId;
HWINSTA hwinstaSave;
HDESK hdeskSave;
HWINSTA hwinstaUser;
HDESK hdeskUser;
LPSTR lpszWindowStation = "WinSta0";

DWORD dwGuiThreadId = 0;

dwTotal = 0;
hDesk = NULL;
printf("\t\t=== Application Task ===\n\n");
GetDesktopWindow();
hwinstaSave = GetProcessWindowStation();
dwThreadId = GetCurrentThreadId();
hdeskSave = GetThreadDesktop(dwThreadId);
hwinstaUser = OpenWindowStation(lpszWindowStation, FALSE, MAXIMUM_ALLOWED);
if (hwinstaUser == NULL)
{
RpcRevertToSelf();
printf("hwinstauser = null\n");
return 0;
}
SetProcessWindowStation(hwinstaUser);
hdeskUser = OpenDesktop(lpszDesktop, 0, FALSE, MAXIMUM_ALLOWED);
RpcRevertToSelf();
if (hdeskUser == NULL)
{
SetProcessWindowStation(hwinstaSave);
printf("hdeskUser = null\n");
CloseWindowStation(hwinstaUser);
return 0;
}
SetThreadDesktop(hdeskUser);
EnumDesktopWindows(hdeskUser,(WNDENUMPROC)EnumWindowProc,0);
printf("Total:\t\t%d\n",dwTotal);
printf("Desktop:\t%s\n",lpszDesktop);
SetThreadDesktop(hdeskSave);
SetProcessWindowStation(hwinstaSave);
CloseDesktop(hdeskUser);
CloseWindowStation(hwinstaUser);

/////////////////////////////////////////////
//getchar();
return 1;
return TRUE;
}

BOOL CALLBACK EnumWindowProc(HWND hWnd,
LPARAM lParam)
{
DWORD dwMaxCount = 250;
DWORD dwTID = 0;
DWORD dwPID = 0;
DWORD dwReturnCount;
TCHAR szWindowText[250];
char *match;
GetDesktopWindow();
if(!IsWindowVisible(hWnd))
{
return TRUE;
}

dwReturnCount = GetWindowText(hWnd,szWindowText,dwMaxCount);
if(dwReturnCount == 0)
{
return TRUE;
}
else
{
dwTotal ++;
}



printf("HWND:\t\t%X\n",hWnd);

dwTID = GetWindowThreadProcessId(hWnd,&dwPID);
printf("Process ID:\t%d\n",dwPID);
printf("Thread ID:\t%d\n",dwTID);
printf("Task:\t\t%s\n\n",szWindowText);
match = strstr(szWindowText,"没有响应");
if (!match)
return TRUE;
else
printf("status: \t\t%s\n",match);
return TRUE;
}

#endif
回复
发动态
发帖子
工具平台和程序库
创建于2007-09-28

2.4w+

社区成员

C/C++ 工具平台和程序库
申请成为版主
社区公告
暂无公告