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

Json from a get API Call C#
c# mvc 5, facebook login - How to ask extra user info after initial login
How do I deal with INSERT parameters which may be null, but are also converted?
Checkbox selection within gridview tossed after postback
XAML customize scrollbar in ListView (UWP)
Translate cURL request with Open SSL Authentication with .PEM file to .NET C#
datetime reset after postback asp net
C#: Block Specific HTML Code
I would like to modify header for all xhr requests
How to correctly use TPL with TcpClient?
Test Local Service Against Production Clients
Set UI element visible in Xamarin C# and then call asynchronous function
WPF TreeView XAML HierarchicalDataTamplate
Umbraco job feed rss
How to sort Arraylist data
C# WPF Application save settings in UserControl

Categories

HOME
pact
sql-server-2014
postgresql-9.3
microcontroller
window.open
confluence-rest-api
handlebars.js
ejb-3.0
runtime
gcloud
adroitlogic
tracking
exchange-transport-agents
brightway
audio-streaming
formulas
javaagents
smali
inline-assembly
uipath
android-cursorloader
utc
hierarchical-data
git-submodules
jms-topic
concrete5
vtd-xml
directions
rtos
webspeech-api
http-proxy
cocoa-scripting
cache-control
perf
kdevelop
hippocms
azure-storage-files
form-fields
matrix-multiplication
redhat-brms
motion
android-graphview
flume-ng
cakephp-3.2
scrapinghub
gridgain
lucee
serialversionuid
standard-error
ear
beanshell
ajv
business-catalyst
tsc
easy-thumbnails
cosign-api
nimbus
angularfire
std
wiql
android-facebook
first-order-logic
pushwoosh
uinavigationitem
autoscaling
android-filterable
azure-mobile-app
firewire
eula
clearquest
tidesdk
mergecursor
iphone-6
drools-guvnor
launcher
report-builder2.0
os.walk
yosemite
system.net
fscanf
disabled-control
debuggervisualizer
html5-filesystem
google-voice
sygic
grape-api
cab
ojb
gmail-imap
derived-class
states
aspmenu-control
event-propagation
nserror
soapexception
hs-err
quazip
excellibrary
mediastreamsource
nscharacterset
database-agnostic
p4.net
webdb
bootstrap-protocol
httpbrowsercapabilities
scalable

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