3
I need to know, from a list of open programs that use BDE for database access, so I want to know if it’s possible and how do I.
Att
Luiz
3
I need to know, from a list of open programs that use BDE for database access, so I want to know if it’s possible and how do I.
Att
Luiz
3
One way to do this is to list the dll
's that the process is using, but if the process has not yet loaded the dll
that you are looking for, this process will not appear in the list, follows function to detect the presence of dll
's in the processes.
uses TlHelp32;
TCardinalArray = array of Cardinal;
ECanContinue = class(Exception);
function EnumerateProcessesThatHasLoadedAModule(const AModuleName: String; IncludeCurrentProcess: Boolean = False): TCardinalArray; forward;
function EnumerateProcessesThatHasLoadedAModule(
const AModuleName: String;
IncludeCurrentProcess: Boolean = False): TCardinalArray;
var
ProcessList: array [0..1023] of DWORD;
I, ProcessCount: Integer;
BytesReturnedInProcessList: DWORD;
CurrentProcessID: Cardinal;
UpperModule: String;
IsModulePresent: Boolean;
function IsModuleDetected(const TargetModuleName: String; PID: DWORD): Boolean;
var
ModuleEntry32: TModuleEntry32;
RetVal, ErrorCode: Cardinal;
HasModule: Boolean;
StrModuleName: String;
begin
Result:= False;
repeat
RetVal:= CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
ErrorCode := ERROR_SUCCESS;
if RetVal = INVALID_HANDLE_VALUE then
begin
ErrorCode:= GetLastError;
if ErrorCode <> ERROR_BAD_LENGTH then
begin
if (ErrorCode = ERROR_ACCESS_DENIED) or (ErrorCode = ERROR_PARTIAL_COPY) then
raise ECanContinue.Create(SysErrorMessage(ErrorCode))
else
RaiseLastOSError;
end;
end;
until ErrorCode <> ERROR_BAD_LENGTH;
try
ModuleEntry32.dwSize := SizeOf(ModuleEntry32);
HasModule:= Integer(Module32First(RetVal, ModuleEntry32)) <> 0;
while HasModule do
begin
StrModuleName := ModuleEntry32.szModule;
Result:= UpperCase(StrModuleName) = TargetModuleName;
if Result then
Break
else
HasModule:= Integer(Module32Next(RetVal, ModuleEntry32)) <> 0;
end;
finally
CloseHandle(RetVal);
end;
end;
begin
SetLength(Result, 0);
CurrentProcessID:= GetCurrentProcessId;
UpperModule:= UpperCase(AModuleName);
if EnumProcesses(@ProcessList, 1024, BytesReturnedInProcessList) then
begin
ProcessCount:= BytesReturnedInProcessList div SizeOf(DWORD);
for I:= 0 to ProcessCount-1 do
begin
if (ConsiderCurrentProcess or (CurrentProcessID <> ProcessList[I])) and
//Ignore Idle 'Fake' Process...
(ProcessList[I] <> 0 ) then
begin
try
IsModulePresent:= IsModuleDetected(UpperModule, ProcessList[I]);
//FROM MSDN:
(*
If the specified process is the Idle process or one of the CSRSS processes,
this function fails and the last error code is ERROR_ACCESS_DENIED because their access restrictions
prevent user-level code from opening them.
*)
except
on E: ECanContinue do
IsModulePresent := False;
else
raise;
end;
if IsModulePresent then
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) -1] := ProcessList[I];
end;
end;
end;
end
else
RaiseLastOSError;
end;
The function call would be like this:
var PIDs: TCardinalArray;
begin
PIDs:= EnumerateProcessesThatHasLoadedAModule('IDAPI32.DLL');
Thank you very much!!!!
@Luizvichiatto No reason, IDAPI32.dll is one of BDE’s dll, I believe that if you use it will always work, I used microsoft’s process explorer to detect this dll
@Luizvichiatto I have not tested this function in 64 bits.
warms not that I test.... I’m with a "shovel" of equipment to test (4) Xp, 7, 8 and 10... I want to see if it will work.... thanks colleague, tomorrow I’ll tell you about the first tests. [s]
Browser other questions tagged delphi delphi-7
You are not signed in. Login or sign up in order to post.
One way to do this is to list the dll’s that the process uses, but if the process has not yet loaded the dll, it would be a false negative, because it would not appear in the list, it would be a problem for you?
– EProgrammerNotFound
It is not necessary to list, I need to know if you have any program using data access with BDE. I’m running the tests with dbiInit, only it informs if Bde is installed.
– Luiz Vichiatto
Excuse me, what I meant is, iterate the loaded modules (DLL’s) and check if there is a BDE dll loaded by the process.
– EProgrammerNotFound
I do not believe there is another way to determine if the BDE is being used, but the solution, as I said, has this exception, when a process has not yet loaded the dll, it would not be considered a BDE user
– EProgrammerNotFound
If even with the deficiency described above, the solution solve your problem, I can encode a function that detects the presence of the BDE dll in a process, this function could return a list of PID’s, the values would be BDE user processes
– EProgrammerNotFound
@Eprogrammernotfound, got it! What type of resource do I need to do, which DLL do I have to search to know if it is being used to request application shutdown?
– Luiz Vichiatto