Using System;
Using System. Collections. Generic;
Using System. serviceprocess;
Using System. configuration. Install;
Static Class Program
{
/// <Summary>
/// ApplicationProgram.
/// </Summary>
[Stathread]
Static Void Main ( String [] ARGs)
{
// Running Service
If (ARGs. Length = 0 )
{
Servicebase [] servicestorun;
Servicestorun = New Servicebase [] { New Myservice1 ()};
Servicebase. Run (servicestorun );
}
// Install services
Else If (ARGs [ 0 ]. Tolower () = " /I " | ARGs [ 0 ]. Tolower () = " -I " )
{
Try
{
String [] Using line = {};
String Servicefilename = System. reflection. Assembly. getexecutingassembly (). location;
Transactedinstaller = New Transactedinstaller ();
Assemblyinstaller = New Assemblyinstaller (servicefilename, cmdline );
Transactedinstaller. installers. Add (assemblyinstaller );
Transactedinstaller. Install ( New System. Collections. hashtable ());
}
Catch (Exception ex)
{
String MSG = Ex. message;
}
}
// Delete a service
Else If (ARGs [ 0 ]. Tolower () = " /U " | ARGs [ 0 ]. Tolower () = " -U " )
{
Try
{
String [] Using line = {};
String Servicefilename = System. reflection. Assembly. getexecutingassembly (). location;
Transactedinstaller = New Transactedinstaller ();
Assemblyinstaller = New Assemblyinstaller (servicefilename, cmdline );
Transactedinstaller. installers. Add (assemblyinstaller );
Transactedinstaller. Uninstall ( Null );
}
Catch (Exception ex)
{
String MSG = Ex. message;
}
}
}
}