Installer - Taking Parameters from Command Line?

  • Thread starter Thread starter Microsoft
  • Start date Start date
M

Microsoft

I'm using installutil.exe to install our service.

However our service works similarily to the way that SQL Server does in that
you can have multiple installs of the service with multiple versions running
as separate services. (good for issolation)

My question is, how would I go about passing parameters from the command
line while installing the service so that it will install itself as the
correct "instance"?

Any help would be greatly helpful.

Thanks,
James Hancock
 
Hi James,

Thanks for posting.

Although we do not have this option for "installutil.exe", we may add a
"Console.ReadLine()" in the constructor of "ProjectInstaller" class. We can
read the service name as a string from the command line:

Console.Write("Please input the service name:");
string serviceName = Console.ReadLine();
this.serviceInstaller1.ServiceName = serviceName;

When we install the service, we will be prompted to input the service name
twice.

However, the method above will not be able to change the
"ServiceBase.ServerName".

"It is crucial that the ServiceInstaller.ServiceName be identical to the
ServiceBase.ServiceName of the class you derived from ServiceBase.
Normally, the value of the ServiceBase.ServiceName property for the service
is set within the Main() function of the service application's executable.
The Service Control Manager uses the ServiceInstaller.ServiceName property
to locate the service within this executable."

http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/h
tml/frlrfSystemServiceProcessServiceInstallerClassTopic.asp?frame=true

The "ServiceBase.ServiceName" is used to write the event log and so on. If
we would like to change the "ServiceBase.ServiceName" as well, we cannot
hard-code it in the service class. This is a little bit more complicated.

I hope the information is useful. Happy Thanksgiving!

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top