Windows Service Install

  • Thread starter Thread starter Vincent Finn
  • Start date Start date
V

Vincent Finn

Hi,

Is there a way of getting a C# windows service to install itself?

By this I mean the way C++ ones did

MyService.exe -service

Having to use the InstallUtil.exe will make installation programs a
bit more awkward (I know you can package it but that seems messy)

Vin
 
Sure. You just have to write the code to do it. Services written in C++
never installed themselves magically; you had to take parameters in the
command line and muck with the service controller.

It should be much easier in C# though.
 
Sure. You just have to write the code to do it. Services written in C++
never installed themselves magically; you had to take parameters in the
command line and muck with the service controller.

It should be much easier in C# though.

That's the part I was wondering about

Is there a way to invoke the installer
I tried
ProjectInstaller pi = new ProjectInstaller();
Hashtable stateSaver = new Hashtable();
pi.Install(stateSaver);

but that throw an exception
the serviceProcessInstaller suceedes but the seviceInstaller fails
with "Object reference not set to an instance of an object."

Vin
 
Got the solution (by created a managed C++ service and seeing what the
wizard gave me) so here it is in case anyone else is reading the
thread

string sExe = typeof(RAPIDHouseKeeper).Assembly.Location;
string sInstallUtil = typeof(object).Assembly.Location;
sInstallUtil = sInstallUtil.Substring(0,
sInstallUtil.LastIndexOf(@"\"));
sInstallUtil += @"\InstallUtil.exe";

AppDomain dom = AppDomain.CreateDomain("execDom");
string[] asArgs = new string[1] {sExe};
dom.ExecuteAssembly(sInstallUtil, null, asArgs);

Vin
 
may i know where you coded it? is it inside the ProjectInstaller.cs file
or is it under the Service.cs file itself?

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top