c#


Inno Setup for Windows service?


I have a .Net Windows service. I want to create an installer to install that windows service.
Basically, it has to do the following:
Pack installutil.exe (Is it required?)
Run installutil.exe MyService.exe
Start MyService
Also, I want to provide an uninstaller which runs the following command:
installutil.exe /u MyService.exe
How to do these using Inno Setup?
You don't need installutil.exe and probably you don't even have rights to redistribute it.
Here is the way I'm doing it in my application:
using System;
using System.Collections.Generic;
using System.Configuration.Install;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
static void Main(string[] args)
{
if (System.Environment.UserInteractive)
{
string parameter = string.Concat(args);
switch (parameter)
{
case "--install":
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
break;
case "--uninstall":
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
break;
}
}
else
{
ServiceBase.Run(new WindowsService());
}
}
Basically you can have your service to install/uninstall on its own by using ManagedInstallerClass as shown in my example.
Then it's just matter of adding into your InnoSetup script something like this:
[Run]
Filename: "{app}\MYSERVICE.EXE"; Parameters: "--install"
[UninstallRun]
Filename: "{app}\MYSERVICE.EXE"; Parameters: "--uninstall"
Here's how i did it:
Exec(ExpandConstant('{dotnet40}\InstallUtil.exe'), ServiceLocation, '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Apparently, Inno setup has the following constants for referencing the .NET folder on your system:
{dotnet11}
{dotnet20}
{dotnet2032}
{dotnet2064}
{dotnet40}
{dotnet4032}
{dotnet4064}
More information available here.
You can use
Exec(
ExpandConstant('{sys}\sc.exe'),
ExpandConstant('create "MyService" binPath= {app}\MyService.exe start= auto DisplayName= "My Service" obj= LocalSystem'),
'',
SW_HIDE,
ewWaitUntilTerminated,
ResultCode
)
to create a service. See "sc.exe" on how to start, stop, check service status, delete service, etc.
If you want to avoid reboots when the user upgrades then you need to stop the service before copying the exe and start again after.
There are some script functions to do this at Service - Functions to Start, Stop, Install, Remove a Service

Related Links

Embedded scripting on the AppStore - use Python, or snake my way in?
Using Expression to call a property and object and determine if the object is null or not
LINQ joining values from different classes
wp7 xna gestures not working
New window replicates
ASP.net C# Return JS Alert from another thread
Asp.net C# Webform forms Generator/Builder [closed]
Lambda event handler scope
Get OS-Version in WinRT Metro App C#
Enumerating DataPoints in view
Switching control backColor fast
How can a view fill a model?
Iterating form controls that are created at runtime
How to use a Resource Image in Word document?
detecting type of generics within generics
Stuck with httpwebrequest usage

Categories

HOME
oauth-2.0
alasql
ide
mifare
redhawksdr
confluence-rest-api
terminal
checkpoint
kohana
travis-ci-cli
cdn
clip-path
cracking
jpql
suitecrm
osrm
solidity
views
aws-devicefarm
monad-transformers
vala
aws-iot
concatenation
datastax-enterprise
my.cnf
grunt-contrib-uglify
utc
mex
launchd
dynamic-memory-allocation
typeclass
azure-table-storage
r-factor
wordpress-rest-api
epub
restler
machine-code
console.readline
yelp
aura-framework
aspnetboilerplate
superclass
intervention
encoder
g77
pyopenssl
cloudconvert
cancan
dynamic-linking
petapoco
overhead
disassembly
msiexec
sqlproj
dimensionality-reduction
jira-agile
cosign-api
normalisation
supervised-learning
apache2-module
sqldataadapter
controlpanel
skscene
javapackager
random-sample
tokudb
eula
tinymce-plugins
parseexception
pymol
chrome-mobile
chunks
alpha-beta-pruning
grunt-contrib-connect
dirname
drawable
ant-contrib
winrun4j
windows-phone-store
db2-connect
scidb
myrrix
caroufredsel
azure-pack
listpicker
dynamic-expresso
dd4t
xcode4.6.3
php-gettext
event-propagation
mysql-connector
towerjs
mscorlib
youtube.net-api
mysql-pconnect
bootstrap-protocol
vista64

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App