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

abraham6057 2003-12-23 03:45:19
这些在linux下很容易得到的信息为什么在windows下如此难以得到
...全文
88 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
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

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧