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

C# inheritance multiple for different children
IList to JSON fails
Convert to Nested JSON C#
Sending List<Object> WCF POST
Export to excel is exporting check box to excel instead of string
Loop iteration of an array string
Impersonate a user using the Session ID
Is it safe to store and update list in asp.net session via static methods?
Change of the edited cell in a datagridview cell
Trying a REST POST call in C# - using Postman code
List object initialization [duplicate]
How to access HttpContext.Current.User custom attributes in the view
Non-nullable property exception when inserting a new entity
Radio button limiting sets
C# MongoDB LINQ: Cannot query nested list
Fill only last 6 month data from current month in second list from first list in linq

Categories

HOME
actionscript-3
javafx
grizzly
intellij-idea
sql-server-2014
pelican
dronekit
gaussian
mediarecorder
glympse
aggregation-framework
restheart
revit-api
vichuploaderbundle
websharper
mongodb-replica-set
tmux
windows-phone
loader
scotty
caldav
hl7-fhir
minimagick
git-branch
typedef
mattermost
functional-dependencies
ckeditor4.x
android-xml
pypy
eclipse-jdt
availability
n1ql
bootcamp
ansible-inventory
kdevelop
multi-user
oracle-bpm-suite
mapquest
jibx
mockserver
gem-fury
blueimp
binary-decision-diagram
superclass
pexpect
gradlew
ocpjp
azure-data-catalog
ocamlbuild
mef
stream-socket-client
cloudconvert
dotnet-cli
enet
reloaddata
vertex-shader
ownership
cedar-bdd
scikit-image
disconnect
weblogic-maven-plugin
innertext
clique
kramdown
newlib
javapackager
edgar
borland-c++
eaaccessory
stderr
esb-toolkit-2.1
tidesdk
genome
parseexception
mathics
sony-xperia
information-hiding
unityvs
nsurlrequest
pnunit
indic
time-frequency
winrun4j
satisfiability
lettuce
xps
cvi
carrier
.net-reflector
xml-validation
xcode5.1
octokit
cab
kohana-orm
jython-2.5
azure-scheduler
removeall
database-restore
zepto
rfc822
invalidoperationexception
linear-interpolation
esi
teamsystem
motordriver
hypertable
blackberry-eclipse-plugin
sup
nsscrollview
diazo
helicontech
umfpack
datarelation
p4.net
pitch-shifting
glassfish-embedded
ihtmldocument2
projectgen

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