我用findwindow做,但是它输入的是窗口名称,而不是进程名。
比如说运行程序project,它的窗口名是project,而进程名是project.exe
我现在要想输入进程名应该怎么做呢?因为有的程序是没有窗口的,它就只有一个在右下角的图标。是不是用其他函数呢?
比如说运行程序project,它的窗口名是project,而进程名是project.exe
我现在要想输入进程名应该怎么做呢?因为有的程序是没有窗口的,它就只有一个在右下角的图标。是不是用其他函数呢?
HANDLE handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
PROCESSENTRY32 Info;
Info.dwSize = sizeof(PROCESSENTRY32);
if(::Process32First(handle,&Info))
{
do
{
strTmp = Info.szExeFile; // 这个就是EXE的名字 lvItem.iSubItem = i++;
lvItem.pszText = const_cast <LPSTR>((LPCSTR)strTmp);
m_Lst.SetItem(&lvItem);
}
while(::Process32Next(handle,&Info));
::CloseHandle(handle);主要函数为三个....三个::后面的...
uses tlhelp32;
var
myHwnd:THandle;
ProID:^Integer;
myHandle:THandle;
begin
myHwnd:=FindWindow(Nil,'project'); //得到窗口句柄
New(ProID);
GetWindowThreadProcessID(MyHwnd,ProID); //得到进程ID
myHandle:=OpenProcess(Process_All_Access,false,ProID^); //得到进程句柄
if myHandle=$24 then
TerminateProcess(myHandle,0);
end;
hMutex:HWND;
Ret:Integer;begin hMutex := CreateMutex(Nil, False, '你要找的exe的名称');
Ret := GetLastError;
if Ret = Error_already_exists then
begin
MessageBox(Application.Handle, '已经有一个程序在本机运行!', '提示', MB_OK OR MB_ICONWARNING);
ReleaseMutex(hMutex) ;
end;
end;