By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!Neither @PID nor the conditional ISAPP seem to be aware of system processes. Is there some built-in way to check for the existence of a system process (besides plowing through the output of TASKLIST)? Could @PID and ISAPP be made to see system processes?
Could @PID and ISAPP be made to see system processes?
No, @ISPROC requires a PID.Would @ISPROC be a possible solution?
Joe
I don't understand. TASKLIST can see system processes and their PIDs. I wrote a little @ISAPP[] plugin (using Toolhelp32Snapshot). It's not much code and if this is a fair test, it's a heck of a lot faster than @PID.Not unless Microsoft changes the Windows security model.
v:\> echo %@isapp[explorer.exe]
2208
v:\> timer & do i=1 to 1000 (echo %@isapp[explorer.exe] > NUL) & timer
Timer 1 on: 20:32:30
Timer 1 off: 20:32:31 Elapsed: 0:00:00.76
v:\> echo %@pid[explorer.exe]
2208
v:\> timer & do i=1 to 1000 (echo %@pid[explorer.exe] > NUL) & timer
Timer 1 on: 20:33:00
Timer 1 off: 20:33:07 Elapsed: 0:00:07.36
v:\> echo %@isapp[svchost.exe]
708
v:\> echo %@pid[svchost.exe]
0
Neither @PID nor the conditional ISAPP seem to be aware of system processes. Is there some built-in way to check for the existence of a system process (besides plowing through the output of TASKLIST)? Could @PID and ISAPP be made to see system processes?
No. My original interest was in TASKENG.EXE. Such a process seems to be created whenever a scheduled task is run. That's OK with me but what bugs me is that TASKENG.EXE always runs for five minutes regardless of whether it has anything to do.I was looking at the @SERVICE variable function, in the FedUtils plugin, which takes a name, and not a PID. Would this be a possible solution?
DWORD PidFromPartialProcessName(LPWSTR szProcess)
{
LPWSTR pSpec = NthArgument(szProcess, 0, NULL, NULL);
if ( pSpec == NULL )
return 0;
StripEnclosingQuotes(pSpec);
DWORD rv = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if ( hSnap == INVALID_HANDLE_VALUE )
return error(GetLastError(), NULL);
PROCESSENTRY32 pe = {sizeof(PROCESSENTRY32), 0};
if ( Process32First(hSnap, &pe) )
{
do
{
if ( stristr(pe.szExeFile, pSpec )
|| !WildcardComparison(pSpec, pe.szExeFile, 0, 1) )
{
rv = pe.th32ProcessID;
break;
}
}
while ( Process32Next(hSnap, &pe) );
}
CloseHandle(hSnap);
return rv;
}
INT WINAPI f_ISAPP ( LPWSTR psz )
{
Sprintf( psz, L"%lu", PidFromPartialProcessName(psz));
return 0;
}
I can't test it here. I read this.I do not have any plans to change this. (CreateToolhelp32Snapshot works badly in Windows x64.)
On x64 you need to change dwFlags in TProcessEntry32 from a DWORD to a ULONG_PTR and then Process32Next will work. its expecting 304 bytes not 300.
How do you do TASKLIST? Whatever you do should suffice for @PID and the conditional ISAPP and allow seeing all processes. IMHO, not being able to see all processes with @PID and ISAPP is a significant limitation.That's not the problem; the issue is that CreateToolhelp32Snapshot in Windows x64 returns sporadically wrong info for 32-bit processes.
I am not convinced that tip is accurate (had you heard it, Rex?). I could find no other mention of it and it seems unlikely that MS wouldn't be aware of such an omission it at this stage of the game. It also seems unlikely that a "dwFlags" parameter would need to be 64 bits considering that the docs say it's "no longer used and is always set to zero".