1. First, add parameters to the main method of the service to determine if the parameter is "-s", then the service will run. Static Void Main ( String [] ARGs)
{
// Running Service
If (ARGs [ 0 ]. Tolower () = " /S " | ARGs [ 0 ]. Tolower () = " -S " )
{
Servicebase [] servicestorun;
Servicestorun = New Servicebase [] { New Myservice1 ()};
Servicebase. Run (servicestorun );
}
}
2. Add the afterinstall event to serviceinstaller1 and modify the Registry to add command line parameters to the service. Private Void Serviceinstaller1_afterinstall ( Object Sender, installeventargs E)
{
// Add the command line parameter-S to the service
Try
{
Registrykey regkey = Registry. localmachine. opensubkey
( @" System \ CurrentControlSet \ Services \ " + Serviceinstaller1.servicename, True );
Object Value = Regkey. getvalue ( " ImagePath " );
If (Value ! = Null )
{
String ImagePath = Value. tostring ();
Regkey. setvalue ( " ImagePath " , ImagePath + " -S " );
Regkey. Flush ();
}
Regkey. Close ();
}
Catch
{}
}