/// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
            this.serviceInstaller1        = new System.ServiceProcess.ServiceInstaller();
            //
            // serviceProcessInstaller1
            //
            this.serviceProcessInstaller1.Account  = System.ServiceProcess.ServiceAccount.LocalSystem;
            this.serviceProcessInstaller1.Password = null;
            this.serviceProcessInstaller1.Username = null;

            //
            // serviceInstaller1
            //

            this.serviceInstaller1.Description   = "Image Service as part of ex1 in AP2";
            this.serviceInstaller1.DisplayName   = "Image Service AP2";
            this.serviceInstaller1.ServiceName   = "ImageService";
            this.serviceInstaller1.StartType     = System.ServiceProcess.ServiceStartMode.Manual;
            this.serviceInstaller1.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.serviceInstaller1_AfterInstall);
            //
            // ProjectInstaller
            //
            this.Installers.AddRange(new System.Configuration.Install.Installer[] {
                this.serviceProcessInstaller1,
                this.serviceInstaller1
            });
        }
Exemplo n.º 2
0
        void Install(String ServiceName, String DisplayName, String Description,
                     System.ServiceProcess.ServiceAccount Account,
                     System.ServiceProcess.ServiceStartMode StartMode)
        {
            System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
            ProcessInstaller.Account = Account;

            System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();

            System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext();
            string processPath = Process.GetCurrentProcess().MainModule.FileName;

            if (processPath != null && processPath.Length > 0)
            {
                System.IO.FileInfo fi = new System.IO.FileInfo(processPath);

                String   path    = String.Format("/assemblypath={0}", fi.FullName);
                String[] cmdline = { path };
                Context = new System.Configuration.Install.InstallContext("", cmdline);
            }

            SINST.Context     = Context;
            SINST.DisplayName = String.Format("{0}", DisplayName);
            SINST.Description = String.Format("{0}", Description);
            SINST.ServiceName = String.Format("{0}", ServiceName);
            SINST.StartType   = StartMode;
            SINST.Parent      = ProcessInstaller;

            //          SINST.ServicesDependedOn = new String[] { "Spooler", "Netlogon", "Netman" };
            SINST.ServicesDependedOn = null;

            System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
            SINST.Install(state);

            using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", ServiceName), true))
            {
                try
                {
                    //                  Object sValue = oKey.GetValue("ImagePath");
                    Object sValue = oKey.GetValue("ImagePath");
                    string str    = string.Format("{0} service", sValue.ToString());
                    oKey.SetValue("ImagePath", str);
                }
                catch (Exception Ex)
                {
                    // System.Windows.Forms.MessageBox.Show(Ex.Message);
                    System.Console.WriteLine("Failed to install {0}", Ex.Message);
                }
            }
        }
Exemplo n.º 3
0
            public void Install(String ServiceName, String DisplayName, String Description,
                                System.ServiceProcess.ServiceAccount Account,
                                System.ServiceProcess.ServiceStartMode StartMode)
            {
                System.ServiceProcess.ServiceProcessInstaller ProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
                ProcessInstaller.Account = Account;

                System.ServiceProcess.ServiceInstaller SINST = new System.ServiceProcess.ServiceInstaller();

                System.Configuration.Install.InstallContext Context = new System.Configuration.Install.InstallContext();
                string processPath = Process.GetCurrentProcess().MainModule.FileName;

                if (processPath != null && processPath.Length > 0)
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(processPath);

                    String   path    = String.Format("/assemblypath={0}", fi.FullName);
                    String[] cmdline = { path };
                    Context = new System.Configuration.Install.InstallContext("", cmdline);
                }

                SINST.Context     = Context;
                SINST.DisplayName = DisplayName;
                SINST.Description = Description;
                SINST.ServiceName = ServiceName;
                SINST.StartType   = StartMode;
                SINST.Parent      = ProcessInstaller;

                System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
                SINST.Install(state);

                using (RegistryKey oKey = Registry.LocalMachine.OpenSubKey(String.Format(@"SYSTEM\CurrentControlSet\Services\{0}", SINST.ServiceName), true))
                {
                    try
                    {
                        Object sValue = oKey.GetValue("ImagePath");
                        oKey.SetValue("ImagePath", sValue);
                    }
                    catch (Exception Ex)
                    {
                    }
                }
            }