How to use exec with parameter to interact with running process being extracted
Solution 1
It appears the 267 is an "invalid directory" error.
Are you sure the Exec is pointing to the proper location?
Personally, I would change your code to the following :
[code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: Integer;
begin
if Exec(ExpandConstant('{app}\myapplication.exe'), 'quit', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
msgbox('True: C:\myapplication\myapplication.exe : ' + IntToStr(ResultCode), mbInformation, MB_OK);
end
else begin
msgbox('False: C:\myapplication\myapplication.exe : ' + SysErrorMessage(ResultCode), mbInformation, MB_OK);
end;
end;
This of course assumes that the existing myapplication.exe is in {app} as well. To be sure, you can always extract the myapplication.exe to the temp directory and run it from there. Something like:
[code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
ResultCode: Integer;
begin
ExtractTemporaryFile('myapplication.exe');
if Exec(ExpandConstant('{tmp}\myapplication.exe'), 'quit', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
msgbox('True: myapplication.exe : ' + IntToStr(ResultCode), mbInformation, MB_OK);
end
else begin
msgbox('False: myapplication.exe : ' + SysErrorMessage(ResultCode), mbInformation, MB_OK);
end;
end;
Solution 2
From the Inno Help...
"Do not include quotes in the Filename parameter; the function will add them automatically."
This one caught me out, too. I created an installer that calls the installer of a 3rd-party product. It worked fine. But the uninstaller had to look in the registry for the UninstallString of the 3rd-party product. The string in the registry contains quotes, so when I passed it to Exec, it failed with error code 267.
The solution was to call: RemoveQuotes(uninstallString);
bgmCoder
Salve! I am a Catholic Religious Brother, and all of my work is for the benefit of our chapels, faithful and priests. Besides my prayers and religious life, much of my practical work is involved in IT. I don't have any income, and have the vows of Poverty, Chastity and Obedience. Please visit our website if you are interested or curious! If you would like to contact me, please use my personal webform. Since you've read all this, if you want to know more, you can read this tidbit; and there is a photo here (that's me in the front).
Updated on June 05, 2022Comments
-
bgmCoder almost 2 years
Salve! Well, I have scoured the web (and Stack Overflow) for an answer. I need help getting my Inno installer to send a commandline with parameters to a running application.
In myapplication_setup.exe I have packed myapplication.exe. Now, myapplication.exe is equipped with the ability to receive commandline parameters. If I launch a second instance with certain parameters, it will pass them to the first instance and then exit its own second instance (both are exited). This lets me use the second instance of myapplication.exe to make the first instance exit. This part works perfectly if I do it from a batch file or cmd box or run box.
Now, I need the installer to call this commandline: "c:\myapplication\myapplication.exe quit" and then check to see if both instances have exited. I might be able to get away with just checking for the second instance that the installer has launched, because they both exit at about the same time. I don't know inno so well, so here is the code I have come up with to do the commandline function. Problem is that I always get the ResultCode of 267 and myapplication has never exited.
The setup program needs to call the exec function and make sure myapplication.exe has exited before it extracts the new version of myapplication.exe.
Could someone look over my code and help me out? Thanks!
[code] function PrepareToInstall(var NeedsRestart: Boolean): String; var ResultCode: Integer; begin if Exec('C:\myapplication\myapplication.exe', 'quit', '{app}', SW_HIDE, ewWaitUntilTerminated, ResultCode) then begin msgbox('True: C:\myapplication\myapplication.exe : ' + IntToStr(ResultCode), mbInformation, MB_OK); end else begin msgbox('False: C:\myapplication\myapplication.exe : ' + IntToStr(ResultCode), mbInformation, MB_OK); SysErrorMessage(ResultCode) end; end;