コード例 #1
0
ファイル: Program.cs プロジェクト: pwndubey77/s7-diff-merge
        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());
                }
            }
        }
コード例 #2
0
        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());
                }

            }

        }