Ejemplo n.º 1
0
        private static bool InstallService()
        {
            bool success = false;

            try
            {
                string           exeFullPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string           workingPath = System.IO.Path.GetDirectoryName(exeFullPath);
                string           logPath     = System.IO.Path.Combine(workingPath, "Install.log");
                ServiceStartMode startmode   = ServiceStartMode.Automatic;
                ServiceAccount   account     = ServiceAccount.LocalService;
                string           username    = "";
                string           password    = "";

                InstallerForm installerForm = new InstallerForm();
                installerForm.StartType   = ServiceStartMode.Automatic;
                installerForm.AccountType = ServiceAccount.User;
                installerForm.BringToFront();
                installerForm.TopMost = true;
                if (installerForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    startmode = installerForm.StartType;
                    account   = installerForm.AccountType;
                    if (installerForm.AccountType == ServiceAccount.User)
                    {
                        username = installerForm.UserName;
                        password = installerForm.Password;
                    }
                }

                Hashtable        savedState         = new Hashtable();
                ProjectInstaller myProjectInstaller = new ProjectInstaller(true);
                InstallContext   myInstallContext   = new InstallContext(logPath, new string[] { });
                myProjectInstaller.Context     = myInstallContext;
                myProjectInstaller.ServiceName = "Mail Aggregator Service";
                myProjectInstaller.DisplayName = "Mail Aggregator Service";
                myProjectInstaller.Description = "Mail Aggregator Service";
                myProjectInstaller.StartType   = startmode;
                myProjectInstaller.Account     = account;
                if (account == ServiceAccount.User)
                {
                    myProjectInstaller.ServiceUsername = username;
                    myProjectInstaller.ServicePassword = password;
                }
                myProjectInstaller.Context.Parameters["AssemblyPath"] = exeFullPath;

                myProjectInstaller.Install(savedState);
                success = true;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Install service", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
            return(success);
        }
Ejemplo n.º 2
0
        public void Execute(object sender, SimPe.Events.ResourceEventArgs e)
        {
            InstallerForm f = new InstallerForm();

            f.ShowDialog();
        }