private void WriteAntivirusExclusions(string enlistmentRoot, string archiveFolderPath, string outputFileName) { string filepath = Path.Combine(archiveFolderPath, outputFileName); try { bool isExcluded; string error; string message = string.Empty; if (AntiVirusExclusions.TryGetIsPathExcluded(enlistmentRoot, out isExcluded, out error)) { message = "Successfully read Defender exclusions. \n "; if (isExcluded) { message += enlistmentRoot + " is excluded."; } else { message += enlistmentRoot + " is not excluded."; } } else { message = "Unable to read Defender exclusions. \n " + error; } File.WriteAllText(filepath, message); } catch (Exception exc) { this.WriteMessage( "Error while gathering Defender exclusion info. \n" + exc.ToString()); } }
public static void CheckAntiVirusExclusion(ITracer tracer, string path, out bool isExcluded, out string errorMessage) { errorMessage = string.Empty; if (AntiVirusExclusions.TryGetIsPathExcluded(path, out isExcluded, out errorMessage)) { if (!isExcluded) { if (AntiVirusExclusions.AddAntiVirusExclusion(path, out errorMessage)) { if (!AntiVirusExclusions.TryGetIsPathExcluded(path, out isExcluded, out errorMessage)) { errorMessage = string.Format("Unable to determine if this repo is excluded from antivirus after adding exclusion: {0}", errorMessage); tracer.RelatedWarning(errorMessage); } } else { errorMessage = string.Format("Could not add this repo to the antivirus exclusion list: {0}", errorMessage); tracer.RelatedWarning(errorMessage); } } } else { errorMessage = string.Format("Unable to determine if this repo is excluded from antivirus: {0}", errorMessage); tracer.RelatedWarning(errorMessage); } }
protected override void Execute(GVFSEnlistment enlistment) { bool isExcluded; string errorMessage; if (AntiVirusExclusions.TryGetIsPathExcluded(enlistment.EnlistmentRoot, out isExcluded, out errorMessage)) { if (!isExcluded) { this.Output.WriteLine( "This repo is not excluded from antivirus.", enlistment.EnlistmentRoot); } } else { this.Output.WriteLine( "Could not check if '{0}' is excluded from anti-virus. Please check to ensure that '{0}' is excluded. Error: {1}", enlistment.EnlistmentRoot, errorMessage); } using (NamedPipeClient pipeClient = new NamedPipeClient(enlistment.NamedPipeName)) { if (!pipeClient.Connect()) { this.ReportErrorAndExit("Unable to connect to GVFS. Try running 'gvfs mount'"); } try { pipeClient.SendRequest(NamedPipeMessages.GetStatus.Request); NamedPipeMessages.GetStatus.Response getStatusResponse = NamedPipeMessages.GetStatus.Response.FromJson(pipeClient.ReadRawResponse()); this.Output.WriteLine("Enlistment root: " + getStatusResponse.EnlistmentRoot); this.Output.WriteLine("Repo URL: " + getStatusResponse.RepoUrl); this.Output.WriteLine("Objects URL: " + getStatusResponse.ObjectsUrl); this.Output.WriteLine("Mount status: " + getStatusResponse.MountStatus); this.Output.WriteLine("GVFS Lock: " + getStatusResponse.LockStatus); this.Output.WriteLine("Background operations: " + getStatusResponse.BackgroundOperationCount); this.Output.WriteLine("Disk layout version: " + getStatusResponse.DiskLayoutVersion); } catch (BrokenPipeException e) { this.ReportErrorAndExit("Unable to communicate with GVFS: " + e.ToString()); } } }
protected void CheckAntiVirusExclusion(GVFSEnlistment enlistment) { bool isExcluded; if (AntiVirusExclusions.TryGetIsPathExcluded(enlistment.EnlistmentRoot, out isExcluded)) { if (!isExcluded) { if (ProcessHelper.IsAdminElevated()) { this.Output.WriteLine(); this.Output.WriteLine("Adding {0} to your antivirus exclusion list", enlistment.EnlistmentRoot); this.Output.WriteLine(); AntiVirusExclusions.AddAntiVirusExclusion(enlistment.EnlistmentRoot); if (!AntiVirusExclusions.TryGetIsPathExcluded(enlistment.EnlistmentRoot, out isExcluded) || !isExcluded) { this.ReportErrorAndExit( "This repo is not excluded from antivirus and we were unable to add it. Add '{0}' to your exclusion list and then run {1} again.", enlistment.EnlistmentRoot, this.VerbName); } } else { this.ReportErrorAndExit( "This repo is not excluded from antivirus. Either re-run {1} with elevated privileges, or add '{0}' to your exclusion list and then run {1} again.", enlistment.EnlistmentRoot, this.VerbName); } } } else { this.Output.WriteLine(); this.Output.WriteLine( "WARNING: Unable to determine if this repo is excluded from antivirus. Please check to ensure that '{0}' is excluded.", enlistment.EnlistmentRoot); this.Output.WriteLine(); } }
protected void CheckAntiVirusExclusion(GVFSEnlistment enlistment) { bool isExcluded; string getError; if (AntiVirusExclusions.TryGetIsPathExcluded(enlistment.EnlistmentRoot, out isExcluded, out getError)) { if (!isExcluded) { string addError; if (!ProcessHelper.IsAdminElevated()) { addError = "Need elevated privileges to add exclusion."; } else if (AntiVirusExclusions.AddAntiVirusExclusion(enlistment.EnlistmentRoot, out addError)) { addError = string.Empty; AntiVirusExclusions.TryGetIsPathExcluded(enlistment.EnlistmentRoot, out isExcluded, out getError); } if (!isExcluded) { this.Output.WriteLine(); this.Output.WriteLine("WARNING: This repo is not excluded from antivirus and we were unable to add an exclusion for it."); if (!string.IsNullOrEmpty(addError)) { this.Output.WriteLine("Unable to add exclusion: " + addError); } this.Output.WriteLine("Please check to make sure that '{0}' is excluded.", enlistment.EnlistmentRoot); this.Output.WriteLine(); } } } else { this.Output.WriteLine(); this.Output.WriteLine("WARNING: Unable to ensure that this repo is excluded from antivirus."); this.Output.WriteLine("Please check to make sure that '{0}' is excluded.", enlistment.EnlistmentRoot); this.Output.WriteLine(); } }
private void CheckAntiVirusExclusion(ITracer tracer, string path) { string errorMessage; bool isExcluded; if (AntiVirusExclusions.TryGetIsPathExcluded(path, out isExcluded, out errorMessage)) { if (!isExcluded) { if (!AntiVirusExclusions.AddAntiVirusExclusion(path, out errorMessage)) { tracer.RelatedError("Could not add this repo to the antivirus exclusion list. Error: {0}", errorMessage); } } } else { tracer.RelatedError("Unable to determine if this repo is excluded from antivirus. Error: {0}", errorMessage); } }
private void CheckAntiVirusExclusion(ITracer tracer, string path) { bool isExcluded; string getError; if (AntiVirusExclusions.TryGetIsPathExcluded(path, out isExcluded, out getError)) { if (!isExcluded) { if (ProcessHelper.IsAdminElevated()) { string addError; if (AntiVirusExclusions.AddAntiVirusExclusion(path, out addError)) { addError = string.Empty; if (!AntiVirusExclusions.TryGetIsPathExcluded(path, out isExcluded, out getError)) { EventMetadata metadata = new EventMetadata(); metadata.Add("getError", getError); metadata.Add("path", path); tracer.RelatedWarning(metadata, "CheckAntiVirusExclusion: Failed to determine if path excluded after adding it"); } } else { EventMetadata metadata = new EventMetadata(); metadata.Add("addError", addError); metadata.Add("path", path); tracer.RelatedWarning(metadata, "CheckAntiVirusExclusion: AddAntiVirusExclusion failed"); } } else { EventMetadata metadata = new EventMetadata(); metadata.Add("path", path); metadata.Add(TracingConstants.MessageKey.InfoMessage, "CheckAntiVirusExclusion: Skipping call to AddAntiVirusExclusion, GVFS is not running with elevation"); tracer.RelatedEvent(EventLevel.Informational, "CheckAntiVirusExclusion_SkipLocalAdd", metadata); } } } else { EventMetadata metadata = new EventMetadata(); metadata.Add("getError", getError); metadata.Add("path", path); tracer.RelatedWarning(metadata, "CheckAntiVirusExclusion: Failed to determine if path excluded"); } string errorMessage = null; if (!isExcluded && !this.Unattended) { if (this.ShowStatusWhileRunning( () => { return(this.ExcludeFromAntiVirusThroughService(path, out errorMessage)); }, string.Format("Excluding '{0}' from antivirus", path))) { isExcluded = true; } else { EventMetadata metadata = new EventMetadata(); metadata.Add("errorMessage", errorMessage); metadata.Add("path", path); tracer.RelatedWarning(metadata, "CheckAntiVirusExclusion: Failed to exclude path through service"); } } if (!isExcluded) { this.Output.WriteLine(); this.Output.WriteLine("WARNING: Unable to ensure that '{0}' is excluded from antivirus", path); if (!string.IsNullOrEmpty(errorMessage)) { this.Output.WriteLine(errorMessage); } this.Output.WriteLine(); } }