Inno setup and NSSM service working integration - windows

I have an application to pack into a setup file with Inno setup. Application must work as a service on Windows. I am using NSSM service manager to get it done in single computer. However in Inno setup package, I couldn't find any trick to make it possible.
Is there anything to do it with NSSM or is it possible to make service working with Inno script?

Download NSSM
Extract Zip file, then copy nssm.exe to your source path (which Inno Setup script get sources from).
Create a bat file to allow nssm set your App as a service as below:
nssm install "ServiceName" "YourAPP.EXE"
nssm set "ServiceName" AppDirectory %CD%
nssm start "ServiceName"
del "%~f0"
Note: del "%~f0" to delete bat file after setup finished, if you don't want that, remove that line from bat file
Add the previous bat file in your source path.
Add new sources to Inno Setup script as below:
[Files]
Source: "..\YOUR-SOURCE-PATH\file.bat"; DestDir: "{app}";
Source: "..\YOUR-SOURCE-PATH\nssm.exe"; DestDir: "{app}";
Add bat file under [Run] section to set service and start your app as below:
Filename: "{app}\file.bat"; \
Flags: nowait postinstall hidewizard runhidden runascurrentuser; \
Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"
I hope it be useful, have to thank #MartinPrikryl

Related

Inno Setup- make sure that directory is NOT readonly? [duplicate]

This question already has an answer here:
How to set permissions of installation folder in Inno Setup
(1 answer)
Closed 18 days ago.
I have an Inno Setup installer which copies some files into Program Files, the [Files] section is set up like this:
[Files]
Source: "Bundled_Files\*"; DestDir: "{commonpf64}\StudioLinked\Romplur\"; Flags: ignoreversion recursesubdirs createallsubdirs; Permissions: users-full;
The files copied from inside Bundled_Files always end up being set to read-only. I've set the permissions to users-full but that doesn't seem to change anything. Is there a way to ensure that files are made NOT read-only?
I tried adding an additional [Dirs] section before the [Files] section like so:
[Dirs]
Name: "{commonpf64}\StudioLinked\Romplur\"; Permissions: users-full;
But this also didn't change the read-only setting on the folders.
Using Inno Setup 6.2.1 on Windows 10. Any help appreciated!
I use the following code to make a subdirectory of my installation directory writable and editable:
[Dirs]
Name: "{app}\MyWritableSubDir"; Permissions: users-modify
However, you should store only data files in any writable directory or sub-directory of "C:\Program Files", never executables: Otherwise this opens a security hole (there is a reason why "C:\Program Files" is read-only for normal users!).
The correct place to store application specific data, as intended by Microsoft, is either the ProgramData directory or the AppData directory. See Where is the correct place to store my application specific data? for a more general discussion.
See https://jrsoftware.org/ishelp/index.php?topic=consts how to use these directories in Inno Setup.

How to set permissions of installation folder in Inno Setup

I am using Inno Setup to create an installer of my application.
On the first run my application is creating an SQLite database but it can't achieve that while the user doesn't have the permission of modify the installation folder.
I managed to set permissions of files:
[Files]
Source: "D:\....\***.jar"; DestDir: "{app}"; \
Flags: ignoreversion; Permissions: users-full
Source: "D:\....\*"; DestDir: "{app}"; \
Flags: ignoreversion recursesubdirs createallsubdirs; Permissions: users-full
But that doesn't help because I need full users permission on installation folder, for example: C:\Program Files\InstallationFolder
The Permissions parameter of the [Files] section entry applies to the installed files only, not to the implicitly created directories.
To change permissions of a folder, use an explicit entry in the [Dirs] section for the {app}:
[Dirs]
Name: {app}; Permissions: users-full
Though it is not a good practice.
In general, Windows applications shall not require write permissions to their folder. That's against Windows guidelines. The application should write data to a user profile folder (C:\Users\username\AppData) or to a common data folder (C:\ProgramData).
See also Application does not work when installed with Inno Setup.
In your specific case, you better run the database creation process as the Administrator (e.g. using the runascurrentuser flag).

Invoke batch file in .msi or .exe

I have a requirement which needs a batch script to be invoked before the .msi or .exe package can deploy files to the desired location. I created a setup project and I am ablr to get a .msi and .exe when I build it. My main concern here is that, when I run the exe or msi, the installer deploys the code to the desired location but I have to stop the service brfore copying and start it back after the files are copied. Is there anyway that I can invoke a batch scrip to stop the service before the files are deployed and then invoke another batch script after the files are deployed. I tried using custom action but didnt work, any suggestions are highly appreciated. Thank you.
#ECHO OFF & ECHO This is an Install.bat
NET STOP "the service"
START /WAIT "Installation in progress..." "The installer.msi"
NET START "the service"

Update blocked binaries after build

I want to copy binaries to stage server as the last step of build. Previously I was doing it for asp.net web sites powered by IIS. There were no problems as IIS doesn't block any boundaries. Now I need to do the same for executable server application (it executes some background tasks) which blocks at least its exe file. So I need somehow to close application, update binaries and then run application again.
What is the best way to achieve it using TeamCity?
I'm seems like your staging server is a windows machine. If that's the case, I'd recommend using two executables from the PsTools Suite (PsKill and PsExec) to kill/start your process. Here's how I would set everything up in TeamCity:
Download the PsTools Suite, and copy the contents of the zip file to a folder on the build server. I'll be using C:\Program Files\PsTools in my example.
Create a batch file that kills the executable server application, copies the appropriate binaries, and starts the application again. The batch file would look something like this:
"C:\Program Files\PsTools\PsKill" -accepteula \computername -u username -p password name_of_process_to_kill.exe
copy files - I'm assuming you copied binaries to your ASP.Net staging site using the command line. If not, I can provide more details later.
"C:\Program Files\PsTools\PsExec" -accepteula \computername -u username -p password -d "path_and_name_of_executable_on_remote_server" optional_commandline_args_here
Add a new command line build step to your TeamCity build configuration that executes the batch file created in step #2.
I hope this helps!
Here is how I solved it. I added Command Line step with following Custom Script:
taskkill /IM MyApplicationProcessName /F
xcopy RelativePathToBuildBinaires PathWhereToDeployBinaries /s /e /y
start PathToMyApplicationExeInDeployFolder
Initially it didn't work as TeamCity build agent worked as service (which do not have UI). Then I disabled service and started build agent as console (by TeamCityFolder/builagent/bin/agent.bat). And it worked.

Jenkins Windows slave failing the Play! framework build

We are using the Play! framework and I've setup our Jenkins CI to run auto-test and other things on a master Unix machine. As a second step I want to setup a windows slave to run some in browser webdriver tests. Unfortunately my build doesn't get to that point. The source checks out fine in the workspace directory. As a first build step I run
play clean
Which seems to fail everytime. I've given full permissions to admin for that directory and I'm running the jenkins slave under that administrator like so
runas /noprofile /user:DOMAIN\Administrator "javaws http://jenkins:8080/computer/Keith/slave-agent.jnlp"
The console output I see from jenkins is:
Building remotely on Keith in workspace C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows
Updating http://svnrepo..
At revision 448
no change for http://svnrepo.. since the previous build
play path is C:\Software\Play\play
Executing C:\Software\Play\play clean "C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows"
[windows] $ C:\Software\Play\play clean "C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows"
Build step 'Play!' marked build as failure
Finished: FAILURE
Note that when I run the command below manually on the windows box it works fine:
C:\Software\Play\play clean "C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows"
Anyone got any ideas what I'm doing wrong?
Thanks!
I had the same problem and I solved it by adding .bat at the end of play path. In your case, you should configure play path in jenkins as C:\Software\Play\play.bat (not just C:\Software\Play\play).

Resources