I've just started using Inno Setup and I have come across a problem where I need to stop and start tomcat using the cmd. However, using the solution i am using is not working for some reason.
What I am trying to accomplish is to.
Stop tomcat using "net stop tomcat6"
Write a string to a xml-file in the tomcat folder.
Start tomcat using "net start tomcat6"
The solution I am trying with is:
if Exec(ExpandConstant('{cmd}'), '/c net stop tomcat6', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
Log('Result code is: ' + IntToStr(ResultCode));
SaveStringToFile(dirPage.Values[0] + '\conf\Catalina\localhost\' + inputPage.Values[0] + '.xml', GenerateXmlString(inputPage.Values[0], inputPage.Values[1], inputPage.Values[2],
inputPage.Values[3], inputPage.Values[4], inputPage.Values[5],
inputPage.Values[6]), False);
Exec(ExpandConstant('{cmd}'), '/c net start tomcat6', '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
end
This however doesn't seem like the right way to go about this problem since is doesn't stop nor start the tomcat service.
These commands works perfectly if I write them manually in the cmd-window.
Sincerely,
Related
I have a setup for installing my application, and I need to run the application after successfully installing. I used postinstall to do this.
but it shows a checkbox and the user can uncheck it. I need to run the application without asking because of it kinda service which needs to runs at startup. if the user unchecked it he needs to restart the PC to launch.
So I can use the Filename: "{app}\myapp.exe" code without any flags in the Run section to launch the application but the problem is, It runs immediately after installing not after the finish button clicked.
The first issue is my application has an instruction window. it shows up at the launch so the setup window goes to the back. And the second issue is my application does not allow terminating unless uninstall becouse it need to run in the background. Setup waiting to process end to finish.
Is there any way to run the application after the finish button click in inno setup?
Simplifying the answer from Run Files and Programs according to custom checkboxes after clicking on Finish Button in Inno Setup, you can use a code like this:
[Code]
function NextButtonClick(CurPageID: Integer): Boolean;
var
ResultCode: Integer;
Path, Msg: string;
begin
if CurPageID = wpFinished then
begin
Path := ExpandConstant('{app}\MyProg.exe');
if ExecAsOriginalUser(Path, '', '', SW_SHOW, ewNoWait, ResultCode) then
begin
Log('Executed MyProg');
end
else
begin
Msg := 'Error executing MyProg - ' + SysErrorMessage(ResultCode);
MsgBox(Msg, mbError, MB_OK);
end;
end;
Result := True;
end;
Replace ExecAsOriginalUser with Exec, if you want to run the program with elevated/Administrator privileges (if the installer uses them at all).
Add code section to your script like this:
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
ResultCode: Integer;
begin
if CurStep = ssDone then
Exec(ExpandConstant('{app}\MyProg.exe'), '', '', SW_SHOW, ewNoWait, ResultCode);
end;
It will be triggered only on a success installation.
Use ExecAsOriginalUser instead of Exec if you don't want the exe run as admin.
I wanna run an application before installing and I'm using this code on Inno Setup Script(Pascal):
function InitializeSetup():boolean;
var
ResultCode: integer;
begin
// Launch Notepad and wait for it to terminate
if ExecAsOriginalUser('{src}\MyFolder\Injector.exe', '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
end
else begin
// handle failure if necessary; ResultCode contains the error code
end;
// Proceed Setup
Result := True;
end;
When I'm using "{win}\notepad.exe", It works but when I use "{src}\MyFolder\Injector.exe", Setup doesn't open my program and continues install.
Note : Injector has app.manifest which has 'requireAdministrator'. However this application should be run as administrator.
So what's wrong?
You need to use the ExpandConstant function when using values such as {src} in code.
However, InitializeSetup is also too early to run installation tasks. You should move this code into CurStepChanged(ssInstall).
Also, if it requires admin permissions it must be run with Exec, not ExecAsOriginalUser.
This May work for you... I believe that this problem is because of spaces in the entire path..that should overcome with double quoting the path...
Exec('cmd.exe','/c "'+ExpandConstant('{src}\MyFolder\Injector.exe')+'"', '',SW_SHOW,ewWaitUntilTerminated, ResultCode);
cheers..
I'm calling cmd to excute java, but the resultcode is always 1,after checking, I found it represents 'incorrect function'.
My code is like:
Exec('cmd', '/c C:\Program Files\jre\bin\java -version','' , SW_HIDE, ewWaitUntilTerminated, ResultCode);
I also call, the following code, it doesn't work either:
Exec('cmd', '/c "C:\Program Files\jre\bin\java -version"','' , SW_HIDE, ewWaitUntilTerminated, ResultCode);
if I call the following code, it works
Exec('cmd', '/c java -version','' , SW_HIDE, ewWaitUntilTerminated, ResultCode);
It seems the the space in the java path` can not be recognized. Does anyone know how to correct it?
Your first attempt failed, due to a space in the file path, which was not enclosed by double quotes. Your second attempt failed because you've enclosed into double quotes except the file path also the passed parameter -version. And, in both cases you are missing .exe at the end of the application path.
You can try it this way instead:
Exec('cmd', '/c ""C:\Program Files\jre\bin\java.exe" -version"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
But, I'm missing here the reason for executing it through the cmd shell. I suppose you can do it directly by calling java.exe this way:
Exec('C:\Program Files\jre\bin\java.exe', '-version', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Just one offtopic note, are you sure the java.exe will be always in C:\Program Files\jre\bin\ ?
I'm write installation package using inno for ms sql script. I have the following code:
strParam := '-U hel -P password -S ServerName -d test -Q "sp_test"';
try
Exec('sqlcmd.exe', strParam, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
result := ResultCode = 0;
except
Exec('osql.exe', strParam, '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
result := ResultCode = 0;
end;
Sp executes ok but black screen with sqlcmd.exe is hanging until either I type exit or close it. I want a window with sqlcmd.exe closed after sp is executed.
You seem to be trying to use sqlcmd first, and then using osql as a backup if that Exec throws. The documentation suggests to me that this won't work at all; you need if not Exec('sqlcmd', ...) then instead,
That aside, we use osql exclusively for our sql updates, and have never had issues with it not terminating. If you don't have a good reason for investing in two separate sql update programs, just use the one that works better. If that happens to be osql, so be it.
I ran into this today. My answer was that I have many differing versions of SQL command and the SQL program files. I took one path statement out for an older version and it started working
is it possible to start a Inno Setup, that waits until the child process has finished? The current systems default behaviour is that the setup starts the "real" setup in temporary folder and goes further in command line. My aim is that the parent process should wait until the child finishes to read out the return code in errorlevel variable. I've made a picture for better understanding
My 2nd question is how Inno handles the setup exit codes. Where can they read out after setup has finished? If an error occurs in setup or user clicks cancel the env-variable %errorlevel% is always 0.
Thanks in advance
What you are trying to do is a function of the OS, not really InnoSetup. Use the following to do what you want from a command prompt or batch file:
start /wait setup.exe
echo %ERRORLEVEL%
The following code sample calls child.exe during the post-install step:
procedure CurStepChanged(CurStep: TSetupStep);
var
ErrorCode: integer;
begin
if (CurStep = ssPostInstall) then
begin
WizardForm.Hide;
ShellExec('open', 'child.exe', '', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode);
WizardForm.Show;
if (ErrorCode <> 0) then
begin
// error handling
end;
end;
end;