Esempio n. 1
0
        private void OnInit(object sender, EventArgs e)
        {
            _infoFile = Utility.GetInfoFile();
            if (File.Exists(_infoFile))
            {
                _infos = ServiceInstaller.DeSerializeObject <ServiceInfos>(_infoFile);
            }
            else
            {
                _infos             = new ServiceInfos();
                _infos.ServiceType = ServiceInstaller.ServiceBootFlag.AutoStart;
                _infos.ServiceName = Utility.GetServiceName();
            }

            tbServiceName.Text = _infos.ServiceName;

            bool   isInstalled = ServiceInstaller.ServiceIsInstalled(tbServiceName.Text);
            bool   isAdmin     = Utility.IsAdministrator();
            string message;

            if (isInstalled)
            {
                if (isAdmin)
                {
                    message = "Service installed ....";
                    btnUninstall.Enabled = true;
                }
                else
                {
                    message = "Service installed, but application not started as Administrator...";
                    btnUninstall.Enabled = false;
                }
            }
            else
            {
                message = "Service not installed ....";
                btnUninstall.Enabled = false;
            }

            lbMessage.Text = message;
        }
        private bool IsValidServiceInfo()
        {
            var infos = GetInfos();

            if (string.IsNullOrWhiteSpace(infos.ServiceName))
            {
                MessageBox.Show("Service Name empty !", "Install Service", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            bool isInstalled = ServiceInstaller.ServiceIsInstalled(infos.ServiceName);
            if (isInstalled)
            {
                MessageBox.Show("Service allready installed !", "Install Service", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            if (string.IsNullOrWhiteSpace(infos.DisplayName))
            {
                MessageBox.Show("Display Name empty !", "Install Service", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            if (string.IsNullOrWhiteSpace(infos.ServiceDescription))
            {
                MessageBox.Show("Display Description empty !", "Install Service", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            if (!Utility.IsAdministrator())
            {
                MessageBox.Show("Service Installation is only possible, when application was started as Administrator !", "Install Service", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return false;
            }

            return true;
        }