Exemplo n.º 1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            //Start Parameters are not implemented
            if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
            {
                ServiceController sc = new ServiceController(serviceName);
                if (sc != null)
                {
                    sc.Start();
                    sc.WaitForStatus(ServiceControllerStatus.Running);
                }
            }
            else
            {
                IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(serviceName);
                if (pHandle != IntPtr.Zero)
                {
                    int iRet = 0;
                    ServiceManagerInteropWrapper.StartAllServiceDependencies(pHandle, ref iRet);
                    ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
                }
            }

            _parentDlg.commit = true;
            SetData();
        }
        public void On_MenuClick(object sender, EventArgs e)
        {
            MenuItem mi = sender as MenuItem;

            if (mi.Text.Trim().Equals("&Refresh"))
            {
                treeNode.IsModified = true;
                treeNode.sc.ShowControl(treeNode);
                return;
            }
            else if (mi.Text.Trim().Equals("&Help"))
            {
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.UseShellExecute = true;
                psi.FileName        = CommonResources.GetString("LAC_Help");
                psi.Verb            = "open";
                psi.WindowStyle     = ProcessWindowStyle.Normal;
                Process.Start(psi);
                return;
            }
            else if (mi.Text.Trim().Equals("&Properties"))
            {
                ServicePropertiesDlg dlg = new ServicePropertiesDlg(base.container, this, plugin, serviceInfo.serviceName.Trim());
                dlg.ShowDialog();

                if (dlg.commit)
                {
                    treeNode.IsModified = true;
                    treeNode.sc.ShowControl(treeNode);
                    return;
                }
            }
            else
            {
                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    switch (mi.Text.Trim())
                    {
                    case "&Restart":
                        ServiceManagerWindowsWrapper.WMIServiceRestart(serviceInfo.serviceName);
                        break;

                    default:
                        Do_WinServiceInvoke(mi.Text.Trim());
                        break;
                    }
                }
                else
                {
                    int    iRet    = 0;
                    IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(mi.Tag as string);
                    switch (mi.Text.Trim())
                    {
                    case "&Restart":
                        if (pHandle != IntPtr.Zero)
                        {
                            iRet = ServiceManagerInteropWrapper.ApiLwSmRefreshService(pHandle);
                        }
                        break;

                    case "&Start":
                        if (pHandle != IntPtr.Zero)
                        {
                            ServiceManagerInteropWrapper.StartAllServiceDependencies(pHandle, ref iRet);
                        }
                        break;

                    case "&Stop":
                        if (pHandle != IntPtr.Zero)
                        {
                            iRet = ServiceManagerInteropWrapper.StopServiceRecursive(pHandle);
                        }
                        break;

                    default:
                        break;
                    }
                    if (iRet == (int)41202)
                    {
                        container.ShowError("The service is unable to start.\nPlease check the all its dependencies are started");
                    }
                    else if (iRet != 0)
                    {
                        container.ShowError("Failed to start the specified service: error code:" + iRet);
                    }

                    ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);

                    if (iRet == 0)
                    {
                        treeNode.IsModified = true;
                        treeNode.sc.ShowControl(treeNode);
                        return;
                    }
                }
            }
        }