/// <summary> /// Performs a repair on the current installed version of the .NET agent via the command line. /// </summary> public void CommandLineRepair(string testName = "") { Common.Log(String.Format("Repairing the .NET Agent"), testName); IISCommand("Stop"); // Make a call to perform the repair FileOperations.DeleteFileOrDirectory(_mgmtScope, @"C:\\repairLog.txt"); if (File.Exists($@"{Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi")) { Common.Log($@"Found {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi", testName); } else { Common.Log($@"ERROR: Did not find: {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi", testName); } var command = $@"msiexec.exe /f {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi /quiet /lv* C:\repairLog.txt"; Common.Log($"MSIEXEC command: {command}", testName); WMI.MakeWMICall(_mgmtScope, "Win32_Process", command); IISCommand("Start"); }
/// <summary> /// Executes the specified command against IIS. /// </summary> /// <param name="command">The command to execute ('Stop', 'Start', or 'Reset').</param> public void IISCommand(String command) { Common.Log($"Executing IIS '{command}' on '{_address}'"); var iisCommand = command == "Reset" ? String.Empty : $" /{command}"; WMI.MakeWMICall(_mgmtScope, "Win32_Process", $@"cmd.exe /c iisreset.exe{iisCommand}"); }
/// <summary> /// Uninstalls the .NET Agent via a WMI call. /// </summary> /// <param name="purge">Flag used to purge remaining file(s) after uninstall.</param> public void CommandLineUninstall(bool purge = false, string testName = "") { Common.Log(String.Format("Uninstalling the .NET Agent"), testName); IISCommand("Stop"); // Uninstall the agent FileOperations.DeleteFileOrDirectory(_mgmtScope, @"C:\\uninstallLog.txt"); if (File.Exists($@"{Settings.Workspace}\build\BuildArtifacts\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi")) { Common.Log($@"Found {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi", testName); } else { Common.Log($@"ERROR: Did not find: {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi", testName); } var command = $@"msiexec.exe /x {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi /norestart /quiet /lv* C:\uninstallLog.txt"; Common.Log($"MSIEXEC command: {command}", testName); WMI.MakeWMICall(_mgmtScope, "Win32_Process", command); // Purge files if specified if (purge) { // Set the file paths var paths = new[] { @"C:\\Program Files\\New Relic", @"C:\\ProgramData\\New Relic" }; // Recursively deleted the specified paths foreach (var path in paths) { FileOperations.DeleteFileOrDirectory(_mgmtScope, path, true); } // Delete the agent environment variables DeleteEnvironmentVariable("COR_ENABLE_PROFILING"); DeleteEnvironmentVariable("COR_PROFILER"); DeleteEnvironmentVariable("COR_PROFILER_PATH"); DeleteEnvironmentVariable("NEWRELIC_HOME"); DeleteEnvironmentVariable("NEW_RELIC_HOME"); DeleteEnvironmentVariable("NEW_RELIC_HOST"); DeleteEnvironmentVariable("NEWRELIC_LICENSEKEY"); // Delete the WAS and W3SVC Environment DeleteRegistryKey(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Services\W3SVC", "Environment"); DeleteRegistryKey(RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Services\WAS", "Environment"); } IISCommand("Start"); }
/// <summary> /// Executes the strong name utility to determine if the specified file is signed. /// </summary> /// <param name="filePath">The path to the file to be checked.</param> /// <returns>Output from the batch script that checks if the .dll is signed.</returns> private string ExecuteIsStronglyNamed(string filePath) { var command = string.Format("cmd.exe /c sn.exe -vf \"{0}\" > C:\\cmdOutput.txt", filePath); WMI.MakeWMICall(TServer.MgmtScope, "Win32_Process", command, @"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\"); var result = FileOperations.ParseTextFile(string.Format(@"{0}\cmdOutput.txt", TServer.DriveRoot)); FileOperations.DeleteFileOrDirectory(TServer.MgmtScope, @"C:\\cmdOutput.txt"); return(result); }
/// <summary> /// Installs the .NET Agent via a command line call to msiexec.exe. /// </summary> /// <param name="licenseKey">The account license key.</param> /// <param name="features">The optional list of features to install.</param> /// <param name="allFeatures">Option to install all options - this will override any/all features specified in the 'features' parameter.</param> public void CommandLineInstall(String licenseKey, List <Enumerations.InstallFeatures> features = null, bool allFeatures = false, bool setCollectorHost = true, string testName = "") { Common.Log(String.Format("Installing the .NET Agent"), testName); IISCommand("Stop"); // Make a wmi call to perform the install var addKey = !String.IsNullOrEmpty(licenseKey) ? $" NR_LICENSE_KEY={licenseKey}" : String.Empty; var featuresList = String.Empty; var command = String.Empty; FileOperations.DeleteFileOrDirectory(_mgmtScope, @"C:\\installLog.txt"); if (File.Exists($@"{Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi")) { Common.Log($@"Found {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi", testName); } else { Common.Log($@"ERROR: Did not find: {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi", testName); } if (allFeatures) { command = $@"msiexec.exe /i {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi /norestart /quiet{addKey} INSTALLLEVEL=50 /lv* C:\installLog.txt"; } else { if (features != null) { featuresList = features.Aggregate(" ADDLOCAL=", (current, feature) => current + (feature.ToString() + ",")); featuresList = featuresList.TrimEnd(','); } command = $@"msiexec.exe /i {Settings.Workspace}\build\BuildArtifacts\\MsiInstaller-x64\NewRelicAgent_{_processorArchitecture}_{Settings.AgentVersion}.msi /norestart /quiet{addKey}{featuresList} /lv* C:\installLog.txt"; } Common.Log($"MSIEXEC command: {command}", testName); WMI.MakeWMICall(_mgmtScope, "Win32_Process", command); if (setCollectorHost) { ModifyOrCreateXmlAttribute("//x:service", "host", "staging-collector.newrelic.com"); } ModifyOrCreateXmlAttribute("//x:configuration/x:log", "level", "debug"); ModifyOrCreateXmlAttribute("//x:configuration/x:log", "auditLog", "true"); IISCommand("Start"); }
/// <summary> /// Installs the .NET Agent via a command line call to msiexec.exe. /// </summary> /// <param name="targetDir">The target directory for the install.</param> public void CommandLineInstallOldInstall() { IISCommand("Stop"); FileOperations.DeleteFileOrDirectory(_mgmtScope, @"C:\\installLogOld.txt"); var command = $@"msiexec.exe /i C:\NewRelicAgent_{_processorArchitecture}_2.8.1.0.msi /norestart /quiet NR_LICENSE_KEY={Settings.LicenseKey} /lv* C:\installLogOld.txt"; Common.Log($"MSIEXEC command: {command}"); WMI.MakeWMICall(_mgmtScope, "Win32_Process", command); var configPath = String.Empty; if (Settings.Environment == Enumerations.EnvironmentSetting.Local) { configPath = @"C:\ProgramData\New Relic\.NET Agent\newrelic.xml"; } else { configPath = $@"\\{_address}\C$\ProgramData\New Relic\.NET Agent\newrelic.xml"; } // Set the host attribute value to staging, audit logging to 'true' ModifyOrCreateXmlAttribute("//x:service", "host", "staging-collector.newrelic.com", configPath); ModifyOrCreateXmlAttribute("//x:configuration/x:log", "auditLog", "true", configPath); // Create the subfolders FileOperations.CreateFileOrDirectory(_mgmtScope, $@"C:\ProgramData\New Relic\.NET Agent\extensions\ExtensionsSubdirectory", true); // Create the files FileOperations.CreateFileOrDirectory(_mgmtScope, $@"C:\ProgramData\New Relic\.NET Agent\logs\Log.txt"); FileOperations.CreateFileOrDirectory(_mgmtScope, $@"C:\ProgramData\New Relic\.NET Agent\extensions\Extensions.txt"); FileOperations.CreateFileOrDirectory(_mgmtScope, $@"C:\ProgramData\New Relic\.NET Agent\extensions\ExtensionsSubdirectory\ExtensionsSubdirectory.txt"); IISCommand("Start"); }