I'm developing an installer for my program for Windows OS.
I'd like the installer to check if MySQL is already installed and if it isn't silently install MySQL before installation is over.
How can I check if MySQL is already on the computer with delphi?
Regarding MySQL server:
HKLM\SOFTWARE\MySQL AB
. But that does not guarantee anything, as this registry key is optional. MySQL really does not require any "complex" installation procedure, like SQL Server. You can download MySQL as an installer, as just a ZIP archive. In last case the registry key will be not created. The similar with services. Using mysqld.exe --install Kitty --defaults-file=c:\mysql.cfg
command line you can create MySQL service with Kitty name. Or even a service may be not created at all.Regarding MySQL client:
libmysql.dll
is "installed", than the libmysql.dll
presence. You can check for libmysql.dll
at Windows folder, at PATH
folders. More simple - you can always put it with your EXE.libmysql.dll
version, supported by EMBT dbExpress driver. So, again, better to put it with your EXE.Check for this registry entry for MySQL if presentHKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB
If you have MySQL installed then this entry should be present.
If you need some thing more, then check for the service if its present
function ServiceIsPresent(sMachine, sService: PChar): Boolean;
var
SCManHandle, SvcHandle: SC_Handle;
begin
// Open service manager handle.
SCManHandle := OpenSCManager(sMachine, nil, SC_MANAGER_CONNECT);
if (SCManHandle > 0) then
begin
SvcHandle := OpenService(SCManHandle, sService, SERVICE_QUERY_STATUS);
// if Service installed
if (SvcHandle > 0) then
begin
Result := True;
CloseServiceHandle(SvcHandle);
end;
else
Result := False;
CloseServiceHandle(SCManHandle);
end;
end;
function call
ServiceGetStatus(nil,'MySQL');
I have picked up this service name from my registry entriesHKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
But be careful while using service check because some people might have different service names for MySQL service.
As in my case I have 2 installations of MySQL hence 2 services are present MySQL,MySQL501.
Hence it will be bit tedious to find out the correct service name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With