Process is running?
Process is running?
Dear friends,
I need to found if a process is running.
I test GetTasks and GetWindow without result.
The process is visible in process folder of task manager and, for example, with pslist.exe of sysinternals freeware utility.
pslist -e <ProcessName> that return:
This solution is not very professional!
Any suggestion is appreciate.
I need to found if a process is running.
I test GetTasks and GetWindow without result.
The process is visible in process folder of task manager and, for example, with pslist.exe of sysinternals freeware utility.
pslist -e <ProcessName> that return:
This solution is not very professional!
Any suggestion is appreciate.
Ciao, best regards,
Ugo
Ugo
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Process is running?
Ugo,
Are you able to find the window of the task using ?
hWnd := FindWindow( 0, cWindowTitle )
MsgInfo( hWnd )
In case that the task does not has a window, then you have to find its process id using EnumProcesses():
http://msdn.microsoft.com/en-us/library ... S.85).aspx
and then, once you have the process id call to TerminateProcess():
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Are you able to find the window of the task using ?
hWnd := FindWindow( 0, cWindowTitle )
MsgInfo( hWnd )
In case that the task does not has a window, then you have to find its process id using EnumProcesses():
http://msdn.microsoft.com/en-us/library ... S.85).aspx
and then, once you have the process id call to TerminateProcess():
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Re: Process is running?
Antonio,
I tested also with GetTasks and GetWindow but nothing.
I need to find when the process is terminated.
My function test continuosly if is running or there are other method?
Where I found documentation of EnumProcesses() for xHarbour and Fivewin?
The process is in background!Antonio Linares wrote:Are you able to find the window of the task using ?
I tested without result!Antonio Linares wrote:hWnd := FindWindow( 0, cWindowTitle )
MsgInfo( hWnd )
I tested also with GetTasks and GetWindow but nothing.
This is the case.Antonio Linares wrote:In case that the task does not has a window, then you have to find its process id using EnumProcesses():
http://msdn.microsoft.com/en-us/library ... S.85).aspx
and then, once you have the process id call to TerminateProcess():
http://msdn.microsoft.com/en-us/library ... S.85).aspx
I need to find when the process is terminated.
My function test continuosly if is running or there are other method?
Where I found documentation of EnumProcesses() for xHarbour and Fivewin?
Ciao, best regards,
Ugo
Ugo
Re: Process is running?
Hi Ugo, this
return an array with all process id and this
return the name of the id process if your user can access.
Code: Select all
HB_FUNC( GETPROCESSLISTARRAY )
{
DWORD aProcesses[1024];
DWORD nBytes;
DWORD nProcesses;
unsigned int i;
if ( EnumProcesses( aProcesses, sizeof(aProcesses), &nBytes ) )
{
nProcesses = nBytes / sizeof(DWORD);
hb_reta( nProcesses - 1 );
for ( i = 0; i < nProcesses; i++ )
{
if ( aProcesses[i] != 0 )
{
hb_stornl(aProcesses[i],-1,i);
}
}
}
else
{
hb_reta( 0 );
}
}
Code: Select all
HB_FUNC( GETPROCESSNAME )
{
DWORD cbNeeded;
HANDLE hProcess;
HMODULE hMod;
TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE, (DWORD) hb_parnl(1) );
if ( hProcess != NULL )
{
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
}
}
CloseHandle(hProcess);
hb_retc(szProcessName);
}
Re: Process is running?
Hi Patrizio,
many thanks for your help.
Is possible to know the id from the ProcessName?
F.E. GetProcessId( cProcessName )
many thanks for your help.
Is possible to know the id from the ProcessName?
F.E. GetProcessId( cProcessName )
Ciao, best regards,
Ugo
Ugo
Re: Process is running?
I don't see an api for find the process by name, i resolve a similar problem with
You can have more processes with the same name, in example svchost.exe.
Code: Select all
FUNC MyFunction(cProcessName)
LOCAL aProcess, hHandle
aProcess := GetProcessListArray()
FOR EACH nHandle IN aProcess
IF AllTrim(Upper(GetProcessName(nHandle))) == AllTrim(Upper(cProcessName))
// ... insert here what you want to do with the process handle
ENDIF
NEXT
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: Process is running?
Ugo,
Does the process uses a window ?
Even if it has no caption, we can find it using FindWindow( cClassName, 0 ) if we know what Windows classname uses to register its window
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Does the process uses a window ?
Even if it has no caption, we can find it using FindWindow( cClassName, 0 ) if we know what Windows classname uses to register its window
http://msdn.microsoft.com/en-us/library ... S.85).aspx
Re: Process is running?
Antonio,
No, it does not use a window!Antonio Linares wrote:Does the process uses a window ?
Ciao, best regards,
Ugo
Ugo
Re: Process is running?
Patrizio,
Many thanks for your help.
I also thought about this solution.Patrizio wrote:I don't see an api for find the process by name, i resolve a similar problem with
Code: Select all
FUNC MyFunction(cProcessName) LOCAL aProcess, hHandle aProcess := GetProcessListArray() FOR EACH nHandle IN aProcess IF AllTrim(Upper(GetProcessName(nHandle))) == AllTrim(Upper(cProcessName)) // ... insert here what you want to do with the process handle ENDIF NEXT
Ok, it is right!Patrizio wrote:You can have more processes with the same name, in example svchost.exe.
Many thanks for your help.
Ciao, best regards,
Ugo
Ugo
Re: Process is running?
I'm having a problem compiling these code samples. I'm getting 'unresolved external symbol' on _EnumProcesses, _EnumProcessModules, _GetModuleBaseName.
Using xHarbour/xBuilder. Do I need to define these functions with DLL command? If so, does anyone have an example of the correct DLL definition?
Thanks,
Randal
Using xHarbour/xBuilder. Do I need to define these functions with DLL command? If so, does anyone have an example of the correct DLL definition?
Thanks,
Randal
Re: Process is running?
Never mind. I resolved the problem by linking psapi.lib.
Randal
Randal