467,075 Members | 979 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

Windows Service Install

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
  • viewed: 4367
Share:
5 Replies
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
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
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
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
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.

Similar topics

18 posts views Thread by jayderk | last post: by
2 posts views Thread by Mark | last post: by
2 posts views Thread by Fan Wang | last post: by
4 posts views Thread by SQLScott | last post: by
4 posts views Thread by tshad | last post: by
6 posts views Thread by BK | last post: by
3 posts views Thread by Claire | last post: by
5 posts views Thread by dm3281 | last post: by
1 post views Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.