Home All Groups Group Topic Archive Search About

Install Windows Service with command line args

Author
21 Nov 2007 9:46 PM
Robert Slaney
I'm trying to install a .NET Windows Service using the ServiceInstaller /
ServiceProcessInstaller classes.  I cannot seem to find a way to specify
command line arguments.

I've looked through ServiceInstaller:Install method using reflector and it
appears that it is not possible.

According to the Win32 doco, the CreateService function in advapi32.dll
should be able to accept arguments to the binaryPath parameter.  However the
Install method does not allow for this.

Author
22 Nov 2007 7:29 AM
Walter Wang [MSFT]
Hi Robert,

It's a known limitation that currently .NET ServiceProcessInstaller doesn't
expose a way to specify a command line to the process. We have to
workaround this by using the SCM (Service Control Manager) directly. Here's
an example in VB.NET:

#Install a Windows service the way YOU want to! - The Code Project - VB.NET
http://www.codeproject.com/vb/net/WindowsServiceInstall.asp


By the way, we can now specify the description in .NET 2.0 (not available
in 1.1) using ServiceProcessInstaller. Here's another article on this:

#BCL Team Blog : Installing a Managed Service with a Custom Name [Robert
Villahermosa]
http://blogs.msdn.com/bclteam/pages/577672.aspx


Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
22 Nov 2007 8:08 PM
Robert Slaney
Thanks Walter,

Just confirming what I suspected.  Just had a look at the .NET 3.5 assembly
list and there has been no change.  Opportunity missed ?

Anyway, we solved this issue inheriting from the ServiceInstaller class then
opening the RegKey directly and amending the ImagePath value to include the
commandline parameters required

Hack... maybe but it worked!!

""Walter Wang [MSFT]"" wrote:

Show quote
> Hi Robert,
>
> It's a known limitation that currently .NET ServiceProcessInstaller doesn't
> expose a way to specify a command line to the process. We have to
> workaround this by using the SCM (Service Control Manager) directly. Here's
> an example in VB.NET:
>
> #Install a Windows service the way YOU want to! - The Code Project - VB.NET
> http://www.codeproject.com/vb/net/WindowsServiceInstall.asp
>
>
> By the way, we can now specify the description in .NET 2.0 (not available
> in 1.1) using ServiceProcessInstaller. Here's another article on this:
>
> #BCL Team Blog : Installing a Managed Service with a Custom Name [Robert
> Villahermosa]
> http://blogs.msdn.com/bclteam/pages/577672.aspx
>
>
> Regards,
> Walter Wang (waw***@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
Author
23 Nov 2007 1:32 AM
Walter Wang [MSFT]
Hi Robert,

Thanks for your quick reply.

We have recorded this post in our database, hopefully it will be added in
future versions.

Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

AddThis Social Bookmark Button