473,382 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Install Windows Service with command line args

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.
Nov 21 '07 #1
3 15448
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/Wi...iceInstall.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 (wa****@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.

Nov 22 '07 #2
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:
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/Wi...iceInstall.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 (wa****@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.

Nov 22 '07 #3
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 (wa****@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.

Nov 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jason Callas | last post by:
I want a single executable to be able to run as a Windows Service or from the command line. Is there a way to do this? How can I tell where I am being started from so I can know how to load...
1
by: Rob Shorney | last post by:
Hi, I need to write a C# windows service that will scan a specified directory every n minutes, the number of minutes needs to be passed in via an argument for examples directoryscanner.exe...
2
by: n_o_s_p_a__m | last post by:
I run my multithreaded classes (class library) in a standard exe host, works with no problems; but once hosted in SCM, the threads are not spawned, yet no exceptions are thrown. Is this some kind...
1
by: Peter Rilling | last post by:
I have an EXE that I would like to be able to run from either the command-line or as a windows service. Is there a way that I can tell which context the program is running in? Basically, if it...
6
by: Microsoft | last post by:
I'm new to CSharp, previously having done all my development in Delphi. I need to create a service, and for the development cycle I wish it to be an interactive service and use message boxes to...
2
by: Fan Wang | last post by:
Hi All, I wrote a windows service with C# as below. But I can't install it with installutil.exe. I got an error message " Exception occurred while initializing the installation:...
1
by: amirmira | last post by:
I would like to set command line arguments to a service at install time. I need to do this because I need to get information from different registry locations depending on my command line argument....
4
by: kkt49 | last post by:
# vim: et sw=4 ts=8 sts from wxPython.wx import * import sys, os, time import pywintypes import win32serviceutil import win32service import win32event import win32process
5
by: Ajith Menon | last post by:
I have to install .NET framework 3.0. I already have .NET Framework 1.1 installed on my machine. I don't want to remove framework 1.1 since some of the critical applications are using it. While...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.