By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,894 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,894 IT Pros & Developers. It's quick & easy.

Windows Service Install

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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.
--
Klaus H. Probst, MVP
http://www.vbbox.com/

"Vincent Finn" <1@2.com> wrote in message
news:m1********************************@4ax.com...
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

Nov 16 '05 #2

P: n/a
On Wed, 23 Jun 2004 11:31:41 -0700, "Klaus H. Probst"
<us*******@vbbox.com> wrote:
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
Nov 16 '05 #3

P: n/a
On Wed, 23 Jun 2004 11:31:41 -0700, "Klaus H. Probst"
<us*******@vbbox.com> wrote:
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
Nov 16 '05 #4

P: n/a
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
Nov 16 '05 #5

P: n/a
may i know where you coded it? is it inside the ProjectInstaller.cs file
or is it under the Service.cs file itself?

thanks

-----------------------------------------------------------
when you fear to fail, you fear something that has not yet happened.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.