Win32 is required, it will be an InnoSetup installer function...
I did it like that:
=====================================
__declspec( dllexport ) int __stdcall IsRunning(char procName[])
{
DWORD processes[4048], i, num;
if ( !EnumProcesses( processes, sizeof(processes), &num ) )
return 0;
num = num / sizeof(DWORD);
for(i=0; i<num; i++)
{
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processes
);
if( !hProcess )
continue;
HMODULE hMod;
DWORD tmp;
BOOL found = FALSE;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &tmp) )
{
TCHAR thisName[MAX_PATH];
GetModuleBaseName( hProcess, hMod, thisName,
sizeof(thisName)/sizeof(TCHAR) );
found = _tcscmp(thisName, procName) ? FALSE : TRUE;
}
CloseHandle( hProcess );
if(found)
return TRUE;
}
return FALSE;
}
=====================================
--
Regards,
Lloyd Dupont
NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
Holger Grund said:
I'm writing my installer which, of course, is a win32 app (no .NET)
I would like to test tthe program is already running (in case of
reinstall/upgrade) and prompt the user to stop the application.
How do I do that?
Basically I would like somthing like Process.GetProcessByName() but
with win32 calls.
As Will has already pointed out there might be better ways to achieve
what
you want. But if you really insist on Win32 equivalent for the .NET API
you might want to take a look at
- Toolhelp (this is a bit fragile but works on down-level platforms)
s. Process32First et. al.
- PSAPI
s. EnumProcesses
- NtQuerySystemInformation
-hg