But there a problem comes, ShellExecute return immediately whatever the msi installer is not done, Is there a way like `ShellExecuteAndWait` ?
@wytwyt02QuoteBut there a problem comes, ShellExecute return immediately whatever the msi installer is not done, Is there a way like `ShellExecuteAndWait` ?
uses JwaWindows, ShellApi; procedure ExecuteAndWait(const AFileName, AParams, ADirectory: WideString; const AWaitForProcess: Boolean = True); var SEInfo: TShellExecuteInfoW; ExitCode: DWORD; begin FillChar(SEInfo, SizeOf(SEInfo), 0) ; SEInfo.cbSize := SizeOf(TShellExecuteInfoW) ; with SEInfo do begin fMask := SEE_MASK_NOCLOSEPROCESS; Wnd := Form1.Handle; lpFile := PWideChar(AFileName); lpParameters := PWideChar(AParams); lpDirectory := PWideChar(ADirectory); nShow := SW_SHOW; end; if ShellExecuteExW(@SEInfo) and (AWaitForProcess) then begin repeat Application.ProcessMessages; GetExitCodeProcess(SEInfo.hProcess, ExitCode) ; until (ExitCode <> STILL_ACTIVE) or Application.Terminated; end; end;
Why not use TProcess and its option poWaitOnExit? https://wiki.freepascal.org/Executing_External_Programs#TProcess
Why not use TProcess and its option poWaitOnExit? https://wiki.freepascal.org/Executing_External_Programs#TProcess
I have tried with TProcess, but msiexec.exe paramters show paramters error dialog to me.You must add parameters one by one, i.e.
... MySQLInstallProcess.Parameters.Add( '/i C:\Users\wuao\AppData\Local\Temp\MYSQL.msi /passive');
Now I have problem with MySQLInstanceConfig.exe:I have tried with TProcess, but msiexec.exe paramters show paramters error dialog to me.You must add parameters one by one, i.e.
... MySQLInstallProcess.Parameters.Add( '/i C:\Users\wuao\AppData\Local\Temp\MYSQL.msi /passive'); I am not 100% sure about what exactly a "parameter" is: Maybe the '/' must be omitted? And maybe the '/i' and 'C:\Users\...' must be merged to ...Parameters.Add('/i C:\Users\wuoa\AppData\Local\temp\MySQL.msi') -- but this is only a few combinations which you easily can sort out.
... MySQLInstallProcess.Parameters.Add('/i'); MySQLInstallProcess.Parameters.Add('C:\Users\wuao\AppData\Local\Temp\MYSQL.msi'); MySQLInstallProcess.Parameters.Add('/passive');
And there is also a deprecated syntax in which the entire command line is passed to parameter "Command line" instead of .Executeable and Parameters.Add, e.g.As I said this is deprecated, but it is worth a try to see if TProcess is doing what you need.
MySQLInstallProcess.CommandLine := 'msiexec.exe /i C:\Users\wuao\AppData\Local\Temp\MYSQL.msi /passive';
Now I have problem with MySQLInstanceConfig.exe:
ConfigurationProcess:=TProcess.Create(nil); ConfigurationProcess.Executable:='.\MySQLInstanceConfig.exe'; ConfigurationProcess.CurrentDirectory:='C:\Program Files\MySQL\MySQL Server 5.5\bin'; ConfigurationProcess.Parameters.Add('-i'); ConfigurationProcess.Parameters.Add('-q'); ConfigurationProcess.Parameters.Add('"-lC:\mysql_install_log.txt"'); ConfigurationProcess.Parameters.Add('"-nMySQL Server 5.5"'); ConfigurationProcess.Parameters.Add('"-pC:\Program Files\MySQL\MySQL Server 5.5"'); ConfigurationProcess.Parameters.Add('-v'); ConfigurationProcess.Parameters.Add('5.5.60'); ConfigurationProcess.Parameters.Add('ServerType=DEVELOPMEN'); ConfigurationProcess.Parameters.Add('DatabaseType=MIXED'); ConfigurationProcess.Parameters.Add('ConnectionUsage=DSS'); ConfigurationProcess.Parameters.Add('Port=3306'); ConfigurationProcess.Parameters.Add('ServiceName=MySQL5.5'); ConfigurationProcess.Parameters.Add('RootPassword=root'); ConfigurationProcess.Parameters.Add('ConnectionCount=50'); ConfigurationProcess.Parameters.Add('Charset=gbk'); ConfigurationProcess.Options := ConfigurationProcess.Options + [poWaitOnExit]; ConfigurationProcess.Execute; ConfigurationProcess.Free;
There is a exception when ConfigurationProcess.Execute, It might Parameters problem, I do not know how to fix. And I think TProcess.Parameters.Add is unnecessary, Not Convenient
Now I have problem with MySQLInstanceConfig.exe:
ConfigurationProcess:=TProcess.Create(nil); ConfigurationProcess.Executable:='.\MySQLInstanceConfig.exe'; ConfigurationProcess.CurrentDirectory:='C:\Program Files\MySQL\MySQL Server 5.5\bin'; ConfigurationProcess.Parameters.Add('-i'); ConfigurationProcess.Parameters.Add('-q'); ConfigurationProcess.Parameters.Add('"-lC:\mysql_install_log.txt"'); ConfigurationProcess.Parameters.Add('"-nMySQL Server 5.5"'); ConfigurationProcess.Parameters.Add('"-pC:\Program Files\MySQL\MySQL Server 5.5"'); ConfigurationProcess.Parameters.Add('-v'); ConfigurationProcess.Parameters.Add('5.5.60'); ConfigurationProcess.Parameters.Add('ServerType=DEVELOPMEN'); ConfigurationProcess.Parameters.Add('DatabaseType=MIXED'); ConfigurationProcess.Parameters.Add('ConnectionUsage=DSS'); ConfigurationProcess.Parameters.Add('Port=3306'); ConfigurationProcess.Parameters.Add('ServiceName=MySQL5.5'); ConfigurationProcess.Parameters.Add('RootPassword=root'); ConfigurationProcess.Parameters.Add('ConnectionCount=50'); ConfigurationProcess.Parameters.Add('Charset=gbk'); ConfigurationProcess.Options := ConfigurationProcess.Options + [poWaitOnExit]; ConfigurationProcess.Execute; ConfigurationProcess.Free;
There is a exception when ConfigurationProcess.Execute, It might Parameters problem, I do not know how to fix. And I think TProcess.Parameters.Add is unnecessary, Not Convenient
I can't help you regarding the exception, but you'll notice the convenience if you adjust your code:
ConfigurationProcess.Parameters.Add('-lC:\mysql_install_log.txt'); ConfigurationProcess.Parameters.Add('-nMySQL Server 5.5'); ConfigurationProcess.Parameters.Add('-pC:\Program Files\MySQL\MySQL Server 5.5');
Notice the missing quotation marks. TProcess will insert them by itself.
And you can also shorting the code a bit more (as you don't reference the process somewhere else):
with TProcess.Create(Nil) do try Executable := '.\MySQLInstanceConfig.exe'; CurrentDirectory := 'C:\Program Files\MySQL\MySQL Server 5.5\bin'; with Parameters do begin Add('-i'); Add('-q'); // etc. end; Options := Options + [poWaitOnExit]; Execute; finally Free; end;
Note: the try … finally block is also called a resource protection block (https://www.freepascal.org/docs-html/current/ref/refse114.html#x229-25100017.3) and ensures that the Free is executed even if an exception is raised between try and finally.
Sounds all so complicated
wp: the separate parameter is like splitting the deprecated commandline on space. It however is easier to describe complicated variants since it doesn't require all kinds of odd ball quoting rules. (which are even more complicated if you try to do it multiplatform)
But in this case tprocess is overkill.
ExecuteProcess('msiexec.exe',['/i','C:\Users\wuao\AppData\Local\Temp\MYSQL.msi','/passive']);
should do the trick.
EOSError = operating system error... Just a wild guess: Maybe your program does not the rights to run this mysql program? (don't know, though, why ShellExecute can...). Try as admin.
maybe it's already been covered but I'll repeat it here if not..
Windows no longer allows direct execution of the File for some items in Windows 10, 7 etc
For example Edge browser can no longer be executed via its EXE...
You need to use the shellExecute with the file in mind via the extension and the Shell will then execute the proper app in the system for it but it will do it under the control of windows, not your app.
So for example
ShellExcute(normal Parms, 'TheInstallerFileName.msi',....)
all you should include is the paths for your files and make no attempt to use a windows EXE..
basically using TProcess etc most likely will not work.
maybe it's already been covered but I'll repeat it here if not..
Windows no longer allows direct execution of the File for some items in Windows 10, 7 etc
For example Edge browser can no longer be executed via its EXE...
You need to use the shellExecute with the file in mind via the extension and the Shell will then execute the proper app in the system for it but it will do it under the control of windows, not your app.
So for example
ShellExcute(normal Parms, 'TheInstallerFileName.msi',....)
all you should include is the paths for your files and make no attempt to use a windows EXE..
basically using TProcess etc most likely will not work.
TProcess is not base on ShellExcute?
I doubt that is the case though, since mysql* doesn't sound like something microsofty.
Tprocess is based on CreateProcess()
I doubt that is the case though, since mysql* doesn't sound like something microsofty.
Tprocess is based on CreateProcess()
What's microsofty?
I doubt that is the case though, since mysql* doesn't sound like something microsofty.
I doubt that is the case though, since mysql* doesn't sound like something microsofty.
True, mysql isn't a Microsoft app, but mysql.msi is going to call the official Windows installer (MSIEXEC), and then the things that Jamie identified are likely going to come into play.
Hi, Mysql msi installed success, Now I need to config the mysql instance, MySQL provide a toll called MySQLInstanceConfig.exe to config, So I tried with:
Seems you missed this is bit: (the boldening is mine)