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
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'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,
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..
Newbie question: I would like to run a powershell script (.ps1) at the end of the inno-setup install. Can anyone give me a tip on where to put this? I want the user prompted to be asked if he wants to run this script.
Oh yes, what this script does is run netsh.exe to open up a port, the script is clever and it grabs Env:username and Env:userdomain from the current context. Would the context be the admin who is running the setup? or would it be the original user that ran the setup.exe?
Another way is to run the script using the ShellExec from the code.
[Files]
Source: "yourPowershell.ps1"; DestDir: "{app}"; Flags: overwritereadonly replacesameversion promptifolder;
[Tasks]
Name: "runpowershell"; Description: "Do you want to run Powershell script?"
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
ErrorCode: Integer;
ReturnCode: Boolean;
begin
if CurStep = ssPostInstall then begin
if(IsTaskSelected('runpowershell')) then begin
ExtractTemporaryFile('yourPowershell.ps1');
ReturnCode := ShellExec('open', '"PowerShell"', ExpandConstant(' -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File "{tmp}\YourPowershell.ps1"'), '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);
if (ReturnCode = False) then
MsgBox('Message about problem. Error code: ' + IntToStr(ErrorCode) + ' ' + SysErrorMessage(ErrorCode), mbInformation, MB_OK);
end;
end;
[Run]
.....; Description: Run Script; Flags: postinstall
(See the help for more details.) By default this will display a checkbox and run under the original user's context (although it depends a bit on how the installer is run).
You might want to reconsider this approach, though; if you are performing a machine-wide install then you should probably open the port machine-wide too. You can do this with pure Inno code calling WinAPIs -- no powershell required. (Which is a good thing, because it might not be installed.)
Alternatively if you want to keep it a per-user setting you should consider making your application prompt the user for a decision on first run. After all, why give an option to only one of the many possible users of your app?
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;