private static void Main(String[] CommandLineArgs) { //Komandozeilenargumente eingegeben??? if (CommandLineArgs.Length > 0) { if (CommandLineArgs[0] == "/install") { //Service hinzufügen TransactedInstaller serviceInstaller; Hashtable stateSaver; InstallContext installContext; ProjectInstaller mi; serviceInstaller = new TransactedInstaller(); stateSaver = new Hashtable(); mi = new ProjectInstaller(); serviceInstaller.Installers.Add(mi); string prgPfad = "\"" + Assembly.GetExecutingAssembly().Location + "\" " + "/service"; installContext = new InstallContext("ServiceInstall.log", null); installContext.Parameters.Add("assemblyPath", prgPfad); serviceInstaller.Context = installContext; try { serviceInstaller.Install(stateSaver); } catch (Exception ex) { MessageBox.Show("Fehler bein installieren des Service: " + ex.ToString()); } } //serviceInstaller.Commit(stateSaver) else if (CommandLineArgs[0] == "/uninstall") { //Service löschen... TransactedInstaller serviceInstaller; Hashtable stateSaver; InstallContext installContext; ProjectInstaller mi; serviceInstaller = new TransactedInstaller(); stateSaver = new Hashtable(); mi = new ProjectInstaller(); serviceInstaller.Installers.Add(mi); string prgPfad = "\"" + Assembly.GetExecutingAssembly().Location + "\" \"" + "/service\""; installContext = new InstallContext("ServiceInstall.log", null); installContext.Parameters.Add("assemblyPath", prgPfad); serviceInstaller.Context = installContext; try { serviceInstaller.Uninstall(null); } catch (Exception ex) { MessageBox.Show("Fehler bein deinstallieren des Service: " + ex.ToString()); } } else if (CommandLineArgs[0] == "/service") { Service service = new Service(); ServiceBase.Run(new ServiceBase[] { service }); } } //Keine Komandozeilenargumente.... else { { Application.Run(new ServiceConfig()); } } }
private static void Main(String[] CommandLineArgs) { //Komandozeilenargumente eingegeben??? if (CommandLineArgs.Length > 0) { if (CommandLineArgs[0] == "/install") { //Service hinzufügen TransactedInstaller serviceInstaller; Hashtable stateSaver; InstallContext installContext; ProjectInstaller mi; serviceInstaller = new TransactedInstaller(); stateSaver = new Hashtable(); mi = new ProjectInstaller(); serviceInstaller.Installers.Add(mi); string prgPfad = "\"" + Assembly.GetExecutingAssembly().Location + "\" " + "/service"; installContext = new InstallContext("ServiceInstall.log", null); installContext.Parameters.Add("assemblyPath", prgPfad); serviceInstaller.Context = installContext; try { serviceInstaller.Install(stateSaver); } catch (Exception ex) { MessageBox.Show("Fehler bein installieren des Service: " + ex.ToString()); } } //serviceInstaller.Commit(stateSaver) else if (CommandLineArgs[0] == "/uninstall") { //Service löschen... TransactedInstaller serviceInstaller; Hashtable stateSaver; InstallContext installContext; ProjectInstaller mi; serviceInstaller = new TransactedInstaller(); stateSaver = new Hashtable(); mi = new ProjectInstaller(); serviceInstaller.Installers.Add(mi); string prgPfad = "\"" + Assembly.GetExecutingAssembly().Location + "\" \"" + "/service\""; installContext = new InstallContext("ServiceInstall.log", null); installContext.Parameters.Add("assemblyPath", prgPfad); serviceInstaller.Context = installContext; try { serviceInstaller.Uninstall(null); } catch (Exception ex) { MessageBox.Show("Fehler bein deinstallieren des Service: " + ex.ToString()); } } else if (CommandLineArgs[0] == "/service") { Service service = new Service(); ServiceBase.Run(new ServiceBase[] {service}); } } //Keine Komandozeilenargumente.... else { { Application.Run(new ServiceConfig()); } } }