예제 #1
0
        /// <summary>
        /// Sets the se service logon right.
        /// </summary>
        /// <param name="wmi">The WMI.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        private bool SetSeServiceLogonRight(WMIServicesManager wmi)
        {
            if (!CDFMonitor.Instance.Config.AppSettings.UseServiceCredentials)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(_creds.UserName) &&
                _creds.Domain != Properties.Resources.SessionName)
            {
                string userName = _creds.UserName.ToString();
                if (!string.IsNullOrEmpty(_creds.Domain) &&
                    !_creds.UserName.Contains(_creds.Domain))
                {
                    userName = string.Format("{0}\\{1}", _creds.Domain, _creds.UserName);
                }

                // get remote path string path = wmi.GetPath(Properties.Resources.ServiceName);

                int id = wmi.RunProcess(string.Format("{0}\\cdfmonitor\\cdfmonitor.exe /seservicelogonright: {1}", wmi.GetSYSTEMROOT(), userName));
                return(wmi.CheckProcess(_processName, id, true) == 0);
            }
            else
            {
                CDFMonitor.LogOutputHandler("skipping seservicelogonright");
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Uns the deploy.
        /// </summary>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool UnDeploy()
        {
            bool   retVal      = true;
            string destination = string.Empty;

            int i = 0;

            do
            {
                i++;

                foreach (string machine in new List <string>(RemoteList.Keys))
                {
                    if (RemoteList[machine] == RemoteStatus.UnDeployed)
                    {
                        CDFMonitor.LogOutputHandler(string.Format("UnDeploy: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine]));
                        continue;
                    }

                    CDFMonitor.LogOutputHandler("UnDeploy: processing machine:" + machine + " state:" +
                                                RemoteList[machine].ToString());
                    WMIServicesManager wmi;
                    destination = "\\\\" + machine + "\\admin$\\cdfmonitor";
                    int pid = 0;

                    if (Ping(machine) &&
                        (wmi = new WMIServicesManager(machine, _creds)) != null &&
                        wmi.Status &&
                        (wmi.IsServiceInstalled(Resources.ServiceName) == WMIServicesManager.ReturnValue.True &&
                         wmi.StopService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success &&
                         wmi.UninstallService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success)
                        | (FileManager.CheckPath(destination, true)
                           &&
                           ((pid = wmi.RunProcess(string.Format("{0}\\cdfmonitor\\cdfmonitor.exe /clean", wmi.GetSYSTEMROOT()))) != 0
                            & wmi.CheckProcess(_processName, pid, true) == 0) &&
                           FileManager.DeleteFolder(destination, false)))
                    {
                        RemoteList[machine] = RemoteStatus.UnDeployed;
                    }
                    else
                    {
                        CDFMonitor.LogOutputHandler("Fail:UnDeploy: unsuccessful.");
                        RemoteList[machine] = RemoteStatus.Error;
                        retVal = false;
                    }

                    if (!CheckProgress(false, machine, i))
                    {
                        return(retVal);
                    }
                }
            }while ((RemoteList.Count(v => v.Value == RemoteStatus.UnDeployed)) != RemoteList.Count && CheckProgress(true, string.Empty, i));

            return(retVal);
        }
예제 #3
0
        /// <summary>
        /// Gathers this instance.
        /// </summary>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
        public bool Gather()
        {
            bool   retVal      = true;
            string source      = string.Empty;
            string destination = string.Empty;

            if (!FileManager.CheckPath(_path, true))
            {
                return(false);
            }

            int i = 0;

            do
            {
                i++;

                foreach (string machine in new List <string>(RemoteList.Keys))
                {
                    if (RemoteList[machine] == RemoteStatus.Gathered)
                    {
                        CDFMonitor.LogOutputHandler(string.Format("Gather: skipping machine {0} because of cached state: {1}", machine, RemoteList[machine]));
                        continue;
                    }

                    CDFMonitor.LogOutputHandler("Gather: processing machine:" + machine + " state:" +
                                                RemoteList[machine].ToString());
                    WMIServicesManager wmi;
                    source      = "\\\\" + machine + "\\admin$\\cdfmonitor";
                    destination = _path + "\\" + machine;
                    int          pid = 0;
                    RemoteStatus rs  = RemoteStatus.Unknown;

                    if (Ping(machine) &&
                        (wmi = new WMIServicesManager(machine, _creds)) != null &&
                        wmi.Status &&
                        (wmi.IsServiceInstalled(Resources.ServiceName) == WMIServicesManager.ReturnValue.True &&
                         ((rs = CheckServiceState(wmi)) != RemoteStatus.Started ||
                          wmi.StopService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success))
                        | (FileManager.CheckPath(source, false) &&
                           (pid = wmi.RunProcess(wmi.GetSYSTEMROOT() + "\\cdfmonitor\\cdfmonitor.exe /zip")) != 0 &&
                           wmi.CheckProcess(_processName, pid, true) == 0 &&
                           FileManager.CopyFiles(FileManager.GetFiles(source, "*.zip", SearchOption.TopDirectoryOnly), destination, true) &&
                           (FileManager.DeleteFiles(FileManager.GetFiles(source, "*.zip", SearchOption.TopDirectoryOnly), true) == FileManager.Results.Success) &&
                           (rs != RemoteStatus.Started ||
                            wmi.StartService(Resources.ServiceName) == WMIServicesManager.ReturnValue.Success)))
                    {
                        RemoteList[machine] = RemoteStatus.Gathered;
                    }
                    else
                    {
                        CDFMonitor.LogOutputHandler("Fail:Gather: unsuccessful.");
                        RemoteList[machine] = RemoteStatus.Error;
                        retVal = false;
                    }

                    if (!CheckProgress(false, machine, i, destination))
                    {
                        return(retVal);
                    }
                }
            }while ((RemoteList.Count(v => v.Value == RemoteStatus.Gathered) != RemoteList.Count) && CheckProgress(true, string.Empty, i));

            return(retVal);
        }