最好替我写成现成的函数:
BOOL IsProgramRunning(const char* szExecute);
调用:if(IsProgramRunning("C:\\Test.exe"))
MessageBox("Running!");
BOOL IsProgramRunning(const char* szExecute);
调用:if(IsProgramRunning("C:\\Test.exe"))
MessageBox("Running!");
解决方案 »
- 高手教我。。提取html文件中的汉字,然后输出到txt文件中
- 局域网聊天系统,模拟QQ做的,顺便散分,顺便收集意见
- 中断CADORecordset的Execute操作
- ADO查询数据
- webbrowser控件 怎么显示资源中的html文件呢
- 高手指点:消息OnSize的用法
- 怎么模拟向其它进程的TreeView指定节点发送鼠标双击消息?
- 100分求vc读写excel时怎么插入超链接问题
- 工控机一般用Win98还是用Win2000?
- #include "stdafx.h"是干什么的?
- 绘图问题,给点意见,谢谢
- 高分求解!菜鸟级的问题“怎样将BYTE *pIn所指的字节流转化为int Array[]中去??
系统进程列表
single interface to enumerate processes//enum process to find a certain module
void CPtbView::IsAppRun(CString modulename)
{
DWORD buf[4096];
DWORD num;
TCHAR filenamebuf[_MAX_PATH+1];
HMODULE hModule;
DWORD cbReturned;
BOOL bret=EnumProcesses(buf,4095,&num);
bool bfound=false;
CString msg;
if(!bret)
{
AfxMessageBox("Error EnumProcesses");
return;
}
for(int i=0;i<(int)num;i++)
{
HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION¦ PROCESS_VM_READ,false,buf[i]);
if(hProcess ==NULL)
continue;
bret=EnumProcessModules(hProcess ,&hModule, sizeof(hModule), &cbReturned );
if(bret)
{
DWORD dwret=GetModuleFileNameEx(hProcess ,hModule,filenamebuf,_MAX_PATH);
CloseHandle( hProcess ) ;
if(dwret==0)
{
msg.Format("%d",GetLastError());
AfxMessageBox(msg);
break;
}
else
{
TCHAR* pfind=_tcsstr(filenamebuf,modulename);
if(pfind)
{
bfound=true;
break;
}
}
}
}
if(bfound)
AfxMessageBox("Found it");
else
AfxMessageBox("Not found");
}void CPtbView::OnViewCheckrun()
{
IsAppRun("notepad.exe");
}
Unregister...(_)可以达到你的要求!
枚举进程的API。
系统进程列表
#include <tlhelp32.h>
#include <stdio.h>BOOL GetProcessList ()
{
HANDLE hProcessSnap = NULL;
BOOL bRet = FALSE;
PROCESSENTRY32 pe32 = {0};
// Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hProcessSnap == INVALID_HANDLE_VALUE)
return (FALSE);
// Fill in the size of the structure before using it. pe32.dwSize = sizeof(PROCESSENTRY32);
// Walk the snapshot of the processes, and for each process,
// display information. if (Process32First(hProcessSnap, &pe32))
{
DWORD dwPriorityClass;
BOOL bGotModule = FALSE;
MODULEENTRY32 me32 = {0};
do
{
bGotModule = GetProcessModule(pe32.th32ProcessID,
pe32.th32ModuleID, &me32, sizeof(MODULEENTRY32)); if (bGotModule)
{
HANDLE hProcess;
// Get the actual priority class.
hProcess = OpenProcess (PROCESS_ALL_ACCESS,
FALSE, pe32.th32ProcessID);
dwPriorityClass = GetPriorityClass (hProcess);
CloseHandle (hProcess); // Print the process's information.
printf( "\nPriority Class Base\t%d\n",
pe32.pcPriClassBase);
printf( "PID\t\t\t%d\n", pe32.th32ProcessID);
printf( "Thread Count\t\t%d\n", pe32.cntThreads);
printf( "Module Name\t\t%s\n", me32.szModule);
printf( "Full Path\t\t%s\n\n", me32.szExePath);
}
}
while (Process32Next(hProcessSnap, &pe32));
bRet = TRUE;
}
else
bRet = FALSE; // could not walk the list of processes
// Do not forget to clean up the snapshot object. CloseHandle (hProcessSnap);
return (bRet);
} Process32First
Retrieves information about the first process encountered in a system snapshot. BOOL WINAPI Process32First(
HANDLE hSnapshot,
LPPROCESSENTRY32 lppe
);
Parameters
hSnapshot
[in] Handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.
lppe
[in/out] Pointer to a PROCESSENTRY32 structure.
Return Values
Returns TRUE if the first entry of the process list has been copied to the buffer or FALSE otherwise. The ERROR_NO_MORE_FILES error value is returned by the GetLastError function if no processes exist or the snapshot does not contain process information.Res
The calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure. Process32First changes dwSize to the number of bytes written to the structure. This will never be greater than the initial value of dwSize, but it may be smaller. If the value is smaller, do not rely on the values of any members whose offsets are greater than this value. To retrieve information about other processes recorded in the same snapshot, use the Process32Next function.For an example, see Taking a Snapshot and Viewing Processes. Requirements
Windows NT/2000 or later: Requires Windows 2000 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Tlhelp32.h.
Library: Use Kernel32.lib.
最后我还是使用FindWindow做的,因为有时候后台进程的名字会被截断。成为"File name.ex"这样的形式