private ServiceInfo GetUnixServiceInfo(string sservicename)
        {
            ServiceInfo serviceInfo = new ServiceInfo();

            serviceInfo.serviceName = lvService.SelectedItems[0].SubItems[0].Text;

            IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(serviceInfo.serviceName);

            if (pHandle != IntPtr.Zero)
            {
                ServiceManagerApi.LW_SERVICE_STATUS serviceStatus = ServiceManagerInteropWrapper.ApiLwSmQueryServiceStatus(pHandle);
                switch (serviceStatus.state)
                {
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STARTING:
                    serviceInfo.IsRunning = true;
                    break;

                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPED:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPING:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_PAUSED:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_DEAD:
                    serviceInfo.IsRunning = false;
                    break;
                }
                ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
            }

            return(serviceInfo);
        }
Esempio n. 2
0
        private void treeViewDependencies_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node = e.Node;

            if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
            {
                if (node != null && node.Nodes.Count == 0)
                {
                    TreeNode[] dependencyServices = ServiceManagerWindowsWrapper.WMIGetDependencyServices(node.Tag as string);
                    if (dependencyServices != null && dependencyServices.Length > 0)
                    {
                        node.Nodes.AddRange(dependencyServices);
                    }
                }
            }
            else
            {
                IntPtr pServiceHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(node.Tag as string);
                ServiceManagerApi.LW_SERVICE_INFO serviceInfo = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pServiceHandle);
                if (serviceInfo.ppwszDependencies != null && serviceInfo.ppwszDependencies.Length != 0)
                {
                    TreeNode[] servicelist = new TreeNode[serviceInfo.ppwszDependencies.Length];
                    for (int idx = 0; idx < serviceInfo.ppwszDependencies.Length; idx++)
                    {
                        servicelist[idx] = new TreeNode(serviceInfo.pwszName);
                    }

                    if (servicelist != null && servicelist.Length != 0)
                    {
                        node.Nodes.AddRange(servicelist);
                    }
                }
                ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pServiceHandle);
            }
        }
Esempio n. 3
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();
        }
Esempio n. 4
0
        private void treeViewDependents_AfterExpand(object sender, TreeViewEventArgs e)
        {
            TreeNode node = e.Node;

            if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
            {
                if (node != null && node.Nodes.Count == 0)
                {
                    TreeNode[] dependentServices = ServiceManagerWindowsWrapper.WMIGetDependentServices(node.Tag as string);
                    if (dependentServices != null && dependentServices.Length > 0)
                    {
                        node.Nodes.AddRange(dependentServices);
                    }
                }
            }
            else
            {
                string[] sServicedepencies = ServiceManagerInteropWrapper.ApiLwSmEnumerateServices();
                if (sServicedepencies != null)
                {
                    foreach (string name in sServicedepencies)
                    {
                        IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(name);
                        if (pHandle != IntPtr.Zero)
                        {
                            ServiceManagerApi.LW_SERVICE_INFO serviceInfo = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pHandle);
                            if (serviceInfo.ppwszDependencies != null && serviceInfo.ppwszDependencies.Length != 0)
                            {
                                foreach (string service in serviceInfo.ppwszDependencies)
                                {
                                    if ((node.Tag as string).Equals(service, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        node.Nodes.Add(service);
                                    }
                                }
                            }
                            ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void btnStop_Click(object sender, EventArgs e)
        {
            if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
            {
                ServiceController sc = new ServiceController(serviceName);
                if (sc != null)
                {
                    sc.Stop();
                    sc.WaitForStatus(ServiceControllerStatus.Stopped);
                }
            }
            else
            {
                IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(serviceName);
                if (pHandle != IntPtr.Zero)
                {
                    ServiceManagerInteropWrapper.StopServiceRecursive(pHandle);
                    ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
                }
            }

            _parentDlg.commit = true;
            SetData();
        }
        public override void Refresh()
        {
            base.Refresh();

            if (plugin == null)
            {
                plugin = pi as ServiceManagerPlugin;
            }

            this.lblCaption.Text = plugin.GetPlugInNode().Text;

            if (plugin.IsConnectionSuccess)
            {
                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    if (!plugin.Do_LogonSCManager())
                    {
                        Logger.Log("Service Control Manager.Refresh(): Failed to authenticate the specified user");
                        return;
                    }
                }
            }
            else
            {
                return;
            }

            if (treeNode.Nodes.Count == 0 || treeNode.IsModified)
            {
                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                {
                    Dictionary <string, string[]> services = ServiceManagerWindowsWrapper.EnumManagementServices();
                    if (services != null && services.Count != 0)
                    {
                        foreach (string name in services.Keys)
                        {
                            ListViewItem lvItem = new ListViewItem(services[name]);
                            lvItem.Tag = name;
                            lvService.Items.Add(lvItem);
                        }
                    }
                }
                else
                {
                    string[] sServiceEnum = ServiceManagerInteropWrapper.ApiLwSmEnumerateServices();
                    if (sServiceEnum != null)
                    {
                        foreach (string name in sServiceEnum)
                        {
                            string serviceState = string.Empty;
                            IntPtr pHandle      = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(name);
                            if (pHandle != IntPtr.Zero)
                            {
                                ServiceManagerApi.LW_SERVICE_INFO   serviceInfo   = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pHandle);
                                ServiceManagerApi.LW_SERVICE_STATUS serviceStatus = ServiceManagerInteropWrapper.ApiLwSmQueryServiceStatus(pHandle);

                                switch (serviceStatus.state)
                                {
                                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_DEAD:
                                    serviceState = "Dead";
                                    break;

                                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_PAUSED:
                                    serviceState = "Paused";
                                    break;

                                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING:
                                    serviceState = "Running";
                                    break;

                                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STARTING:
                                    serviceState = "Starting";
                                    break;

                                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPED:
                                    serviceState = "Stopped";
                                    break;

                                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPING:
                                    serviceState = "Stopping";
                                    break;
                                }

                                ListViewItem lvItem = new ListViewItem(new string[] { name,
                                                                                      serviceInfo.pwszDescription,
                                                                                      serviceState,
                                                                                      (serviceInfo.bAutostart)?"Automatic": "Manual",
                                                                                      "root" });
                                lvItem.Tag = name;
                                lvService.Items.Add(lvItem);

                                ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
                            }
                        }
                    }
                }
            }

            lvService.Columns[lvService.Columns.Count - 1].Width = 200;
        }
        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;
                    }
                }
            }
        }
Esempio n. 8
0
        private void GetUnixServiceDependencies()
        {
            IntPtr pServiceHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(serviceName);

            if (pServiceHandle == IntPtr.Zero)
            {
                return;
            }

            //Counting of Dependencies
            ServiceManagerApi.LW_SERVICE_INFO serviceInfo = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pServiceHandle);
            if (serviceInfo.ppwszDependencies != null && serviceInfo.ppwszDependencies.Length != 0)
            {
                TreeNode[] servicelist = new TreeNode[serviceInfo.ppwszDependencies.Length];
                for (int idx = 0; idx < serviceInfo.ppwszDependencies.Length; idx++)
                {
                    TreeNode tn = new TreeNode(serviceInfo.ppwszDependencies[idx]);
                    tn.Tag           = serviceInfo.pwszName;
                    servicelist[idx] = tn;
                }

                if (servicelist != null && servicelist.Length != 0)
                {
                    treeViewDependencies.Nodes.AddRange(servicelist);
                }
                else
                {
                    treeViewDependencies.Nodes.Add(new TreeNode("<No Dependencies>"));
                }
            }
            ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pServiceHandle);

            //Counting of Dependents
            List <TreeNode> dependentservices = new List <TreeNode>();

            string[] sServiceEnum = ServiceManagerInteropWrapper.ApiLwSmEnumerateServices();
            if (sServiceEnum != null)
            {
                foreach (string name in sServiceEnum)
                {
                    IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(name);
                    if (pHandle != IntPtr.Zero)
                    {
                        serviceInfo = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pHandle);

                        if (serviceInfo.ppwszDependencies != null && serviceInfo.ppwszDependencies.Length != 0)
                        {
                            foreach (string service in serviceInfo.ppwszDependencies)
                            {
                                if (serviceName.Equals(service, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    TreeNode tn = new TreeNode(name);
                                    tn.Tag = name;
                                    dependentservices.Add(tn);
                                    break;
                                }
                            }
                        }
                        ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
                    }
                }

                if (dependentservices.Count != 0)
                {
                    TreeNode[] services = new TreeNode[dependentservices.Count];
                    dependentservices.CopyTo(services);
                    treeViewDependents.Nodes.AddRange(services);
                }
                else
                {
                    treeViewDependents.Nodes.Add(new TreeNode("<No Dependencies>"));
                }
            }
        }
Esempio n. 9
0
        private void GetUnixServiceInfo()
        {
            txtStartParameters.Text = string.Empty;
            IntPtr pHandle = ServiceManagerInteropWrapper.ApiLwSmAcquireServiceHandle(serviceName);

            if (pHandle != IntPtr.Zero)
            {
                string sArgs = string.Empty;
                ServiceManagerApi.LW_SERVICE_STATUS serviceStatus = ServiceManagerInteropWrapper.ApiLwSmQueryServiceStatus(pHandle);
                ServiceManagerApi.LW_SERVICE_INFO   serviceInfo   = ServiceManagerInteropWrapper.ApiLwSmQueryServiceInfo(pHandle);

                lblServiceNameValue.Text = serviceName;
                txtDisplayName.Text      = serviceInfo.pwszName;
                txtDescription.Text      = serviceInfo.pwszDescription;
                txtPathToExecute.Text    = serviceInfo.pwszPath;

                foreach (string args in serviceInfo.ppwszArgs)
                {
                    txtStartParameters.Text += " " + args;
                }

                txtStartParameters.Text = txtStartParameters.Text.Trim();
                btnPause.Visible        = btnResume.Visible = false;

                cmbStartupType.SelectedIndex = serviceInfo.bAutostart ? 0 : 1;

                switch (serviceStatus.state)
                {
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_DEAD:
                    lblServiceStatusValue.Text = "Dead";
                    break;

                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_PAUSED:
                    lblServiceStatusValue.Text = "Paused";
                    break;

                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING:
                    lblServiceStatusValue.Text = "Running";
                    break;

                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STARTING:
                    lblServiceStatusValue.Text = "Starting";
                    break;

                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPED:
                    lblServiceStatusValue.Text = "Stopped";
                    break;

                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPING:
                    lblServiceStatusValue.Text = "Stopping";
                    break;
                }

                switch (serviceStatus.state)
                {
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_RUNNING:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STARTING:
                    btnStart.Enabled = false;
                    btnStop.Enabled  = true;
                    break;


                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPED:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_STOPPING:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_PAUSED:
                case ServiceManagerApi.LW_SERVICE_STATE.LW_SERVICE_STATE_DEAD:
                    btnStart.Enabled = true;
                    btnStop.Enabled  = false;
                    break;
                }
                ServiceManagerInteropWrapper.ApiLwSmReleaseServiceHandle(pHandle);
            }
        }