Exemplo n.º 1
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            try
            {
                foreach (var device in devlist)
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        continue;
                    }

                    if (FileAndFolderServices.ValidateDirectoryExists(device, GpoCacheDir, ActionName, Logger))
                    {
                        var dirtyContents = Directory.EnumerateDirectories($"\\\\{device}\\C${GpoCacheDir}").ToList();
                        var contents      = new List <string>();

                        foreach (var directory in dirtyContents)
                        {
                            var cleanedPath = $"{GpoCacheDir}\\{directory.Substring(directory.LastIndexOf("\\") + 1)}";
                            contents.Add(cleanedPath);
                        }

                        foreach (var dir in contents)
                        {
                            FileAndFolderServices.CleanDirectory(device, dir, Logger);
                        }

                        _psExecServices.RunOnDeviceWithoutAuthentication(device, "cmd.exe /C gpupdate.exe /force");
                    }
                    else
                    {
                        ResultConsole.AddConsoleLine(
                            "Unable to validate the directory for the GPO cache. Please delete manually.");
                    }
                }
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }
Exemplo n.º 2
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            try
            {
                Parallel.ForEach(devlist, (device) =>
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        return;
                    }

                    if (FileAndFolderServices.ValidateDirectoryExists(device, CcmCachePath, ActionName, Logger))
                    {
                        FileAndFolderServices.CleanDirectory(device, CcmCachePath, Logger);
                    }

                    if (FileAndFolderServices.ValidateDirectoryExists(device, WindowsTemp, ActionName, Logger))
                    {
                        FileAndFolderServices.CleanDirectory(device, WindowsTemp, Logger);
                    }

                    var userDirPaths = Directory.EnumerateDirectories($"\\\\{device}\\C${UsersDirectory}").ToList();
                    var userFolders  = new List <string>();

                    // Create useable paths
                    foreach (var userDir in userDirPaths)
                    {
                        var cleanedPath = $"{UsersDirectory}\\{userDir.Substring(userDir.LastIndexOf("\\") + 1)}";
                        userFolders.Add(cleanedPath);
                    }

                    foreach (var userFolder in userFolders)
                    {
                        if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder, ActionName, Logger))
                        {
                            // Validate and Clean User Temp Folder at "C:\users\[user]\appdata\local\temp"
                            if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder + UserTemp, ActionName, Logger))
                            {
                                FileAndFolderServices.CleanDirectory(device, userFolder + UserTemp, Logger);
                            }

                            // Validate and Clean User Temporary Internet Files at "C:\Users\[user]\AppData\Local\Microsoft\Windows\Temporary Internet Files"
                            if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder + UserTempInternetFiles, ActionName, Logger))
                            {
                                FileAndFolderServices.CleanDirectory(device, userFolder + UserTempInternetFiles, Logger);
                            }

                            // Validate and Clean User Java Cache Files at "C:\Users\[user]\AppData\Local\Microsoft\Windows\Temporary Internet Files"
                            if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder + JavaCache, ActionName, Logger))
                            {
                                FileAndFolderServices.CleanDirectory(device, userFolder + JavaCache, Logger);
                            }
                        }
                    }
                });
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }
Exemplo n.º 3
0
        private void CallbackMethod()
        {
            var failedlist = new List <string>();

            try
            {
                Parallel.ForEach(_parsedListCache, (device) =>
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        return;
                    }

                    var fileName = fileCopyContextCache.FilePath.Split(new char[] { '\\' }).Last();

                    string destPath;
                    if (string.IsNullOrWhiteSpace(fileCopyContextCache.DestinationPath))
                    {
                        destPath = $"\\\\{device}\\C$\\";
                    }
                    else
                    {
                        if (fileCopyContextCache.DestinationPath.StartsWith("\\"))
                        {
                            fileCopyContextCache.DestinationPath = fileCopyContextCache.DestinationPath.Remove(0, 1);
                        }

                        if (fileCopyContextCache.DestinationPath.EndsWith("\\"))
                        {
                            fileCopyContextCache.DestinationPath = fileCopyContextCache.DestinationPath.Remove(fileCopyContextCache.DestinationPath.Length - 1, 1);
                        }

                        destPath = $"\\\\{device}\\C$\\{fileCopyContextCache.DestinationPath}\\";
                    }

                    ResultConsole.AddConsoleLine($"Copying file {fileName} to device {device}");

                    try
                    {
                        if (FileAndFolderServices.ValidateDirectoryExists(device, fileCopyContextCache.DestinationPath, ActionName, Logger))
                        {
                            File.Copy(fileCopyContextCache.FilePath, destPath + fileName, fileCopyContextCache.Overwrite);
                            Logger.LogMessage($"Copied file {fileName} to {destPath}");
                        }
                        else if (fileCopyContextCache.CreateDestination)
                        {
                            Logger.LogMessage($"Creating directory {fileCopyContextCache.DestinationPath}");
                            Directory.CreateDirectory(destPath);

                            Thread.Sleep(100);

                            File.Copy(fileCopyContextCache.FilePath, destPath + fileName, fileCopyContextCache.Overwrite);
                        }
                        else
                        {
                            ResultConsole.AddConsoleLine("Unable to copy, destination doesn't exist.");
                            Logger.LogMessage("Unable to copy, destination doesn't exist.");
                        }
                    }
                    catch (Exception e)
                    {
                        ResultConsole.AddConsoleLine($"Unable to copy file {fileName}. Error: {e.Message}");
                        Logger.LogWarning($"Unable to copy file {fileName}.", e);
                    }
                });
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }
Exemplo n.º 4
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            try
            {
                Parallel.ForEach(devlist, (device) =>
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        return;
                    }

                    var sc = new ServiceController(UpdateService, device);

                    ResultConsole.Instance.AddConsoleLine($"Stopping update service on device {device}");
                    if (sc.Status == ServiceControllerStatus.Running)
                    {
                        sc.Stop();
                        sc.WaitForStatus(ServiceControllerStatus.Stopped, _timeouTimeSpan);
                        ResultConsole.Instance.AddConsoleLine($"Update service stopped on device {device}");
                    }
                    else
                    {
                        ResultConsole.Instance.AddConsoleLine($"Update service not running on device {device}. Continuing...");
                    }

                    var remotepath = $"\\\\{device}\\C$\\{SoftwareDistributionPath}";

                    if (FileAndFolderServices.ValidateDirectoryExists(device, SoftwareDistributionPath, ActionName, Logger))
                    {
                        var contentsList = Directory.GetFileSystemEntries(remotepath).ToList();
                        if (contentsList?.Count > 0)
                        {
                            foreach (var str in contentsList)
                            {
                                var isdir = File.Exists(str);
                                if (isdir)
                                {
                                    File.Delete(str);
                                    continue;
                                }

                                Directory.Delete(str, true);
                            }
                        }
                    }

                    ResultConsole.Instance.AddConsoleLine($"Starting update service on device {device}");
                    sc.Start();
                    sc.WaitForStatus(ServiceControllerStatus.Running, _timeouTimeSpan);
                    ResultConsole.Instance.AddConsoleLine($"Update service started on device {device}");
                });
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }