Ejemplo n.º 1
0
        public bool RepairRemoteWmi(string hostname, CredToken credentialToken)
        {
            _logger.LogMessage($"Attempting to repair WMI on device {hostname}");
            ResultConsole.Instance.AddConsoleLine($"Attempting to repair WMI on device {hostname}");

            var remoteBatchPath  = $"\\\\{hostname}\\C$\\temp\\fixwmi.bat";
            var commandline      = @"-i cmd /c C:\temp\fixwmi.bat"; // -i flag is required for PSExec to push the command through successfully.
            var batchFileContent = CreateWmiRepairBatchConent();

            try
            {
                _logger.LogMessage("Creating remote batch file");
                _fileAndFolderServices.CreateRemoteTextFile(remoteBatchPath, batchFileContent, _logger);
            }
            catch (Exception ex)
            {
                _logger.LogError("Error creating remote WMI repair batch file.", ex);
                ResultConsole.Instance.AddConsoleLine($"Error creating remote WMI repair batch file. Exception thrown: {ex.Message}");
                return(false);
            }

            try
            {
                _logger.LogMessage($"Run WMI repair batch on remote device {hostname}");
                _psExecServices.RunOnDeviceWithAuthentication(hostname, commandline, credentialToken);
                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error running remote batch file on device {hostname}", ex);
                ResultConsole.Instance.AddConsoleLine($"Error running remote batch file on device {hostname}\n Exception: {ex.Message}");
                return(false);
            }
        }