public void TestMethod2() { using (var notepad = new WmiProcess(Environment.SystemDirectory + "\\notepad.exe", "localhost")) { Thread.Sleep(500); notepad.Start(); } }
public DeploymentResult Execute() { var result = new DeploymentResult(); var p = Path.Combine(ExecutableIsLocatedAt, Command); ProcessReturnCode returnCode = WmiProcess.Run(Machine, Command, Args, ExecutableIsLocatedAt); //TODO: Get the output file. Parse it out to get ERRORS and other things and add them to the results if (returnCode != ProcessReturnCode.Success) { result.AddError(_status[(int)returnCode] + " (" + p + ")"); } return(result); }
public DeploymentResult Execute() { var result = new DeploymentResult(); var p = Path.Combine(ExecutableIsLocatedAt, Command); ProcessReturnCode returnCode = WmiProcess.Run(Machine, Command, Args, ExecutableIsLocatedAt); //TODO: how can I get the output back from the computer? if (returnCode != ProcessReturnCode.Success) { result.AddError(_status[(int)returnCode]); } return(result); }
private static async Task DeployConsole(MachineViewModel viewModel) { viewModel.Log.Add(new LogViewModel(LogLevel.Information, $"Logining to {viewModel.Host}")); using (new Impersonation(viewModel.User.Split('\\')[0], viewModel.User.Split('\\')[1], viewModel.Pass)) { viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Killing Admin Console")); await WmiProcess.KillAsync("Norskale Administration Console.exe", viewModel.Host, viewModel.User, viewModel.Pass); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Copy binaries")); await Task.Factory.StartNew( () => DirectoryCopy(viewModel.Path, $@"\\{viewModel.Host}\C$\Program Files (x86)\Norskale\Norskale Administration Console\", true)); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Done")); } }
private static string GetTitle(string processName, int processId, string serverName, string userName, string password, bool useWmi) { if (string.IsNullOrEmpty(processName) || !useWmi) { return(string.Empty); } WmiProcess process = GetWmiProcesses(serverName, userName, password)?.FirstOrDefault(p => p.ProcessId == processId); if (process == null) { return(String.Empty); } if (processName.StartsWith("w3wp", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(process.CommandLine)) { int startIndex = process.CommandLine.IndexOf("-ap ", StringComparison.Ordinal) + 5; //remove the -ap as well as the space and the " if (startIndex == -1) { return(process.CommandLine); } int endIndex = process.CommandLine.IndexOf("\" -", startIndex, StringComparison.Ordinal); //remove the closing " return(TitlePrefix + process.CommandLine.Substring(startIndex, endIndex - startIndex)); } if (string.Equals(processName, "iisexpress.exe", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(process.CommandLine)) { int startIndex = process.CommandLine.IndexOf("/site:", StringComparison.Ordinal) + 7; //remove the /site: as well as the " if (startIndex == -1) { return(string.Empty); } int endIndex = process.CommandLine.IndexOf("\"", startIndex + 7, StringComparison.Ordinal); //remove the closing " return(TitlePrefix + process.CommandLine.Substring(startIndex, endIndex - startIndex)); } if (processName.Contains("WebDev") && !string.IsNullOrEmpty(process.CommandLine)) { var startIndex = process.CommandLine.IndexOf("/port:", StringComparison.Ordinal) + 6; //remove the /site: as well as the " if (startIndex == -1) { return(string.Empty); } var endIndex = process.CommandLine.IndexOf(" ", startIndex, StringComparison.Ordinal); //remove the closing " return(TitlePrefix + process.CommandLine.Substring(startIndex, endIndex - startIndex)); } return(process.CommandLine); }
private static async Task DeployBroker(MachineViewModel viewModel) { viewModel.Log.Add(new LogViewModel(LogLevel.Information, $"Logining to {viewModel.Host}")); using (new Impersonation(viewModel.User.Split('\\')[0], viewModel.User.Split('\\')[1], viewModel.Pass)) { viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Stopping Broker Service")); var service = new ServiceController("Norskale Infrastructure Service", viewModel.Host); await Task.Factory.StartNew( () => { if (service.Status != ServiceControllerStatus.Stopped) { service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped); } }); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Killing Broker tools")); var configToolTask = WmiProcess.KillAsync("Norskale Broker Service Configuration Utility.exe", viewModel.Host, viewModel.User, viewModel.Pass); var dbToolTask = WmiProcess.KillAsync("Norskale Database Management Utility.exe", viewModel.Host, viewModel.User, viewModel.Pass); await Task.WhenAll(configToolTask, dbToolTask); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Copy binaries")); await Task.Factory.StartNew( () => DirectoryCopy(viewModel.Path, $@"\\{viewModel.Host}\C$\Program Files (x86)\Norskale\Norskale Infrastructure Services\", true)); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Starting Service")); await Task.Factory.StartNew( () => { service.Start(); service.WaitForStatus(ServiceControllerStatus.Running); }); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Done")); } }
private static async Task DeployAgent(MachineViewModel viewModel) { viewModel.Log.Add(new LogViewModel(LogLevel.Information, $"Logining to {viewModel.Host}")); using (new Impersonation(viewModel.User.Split('\\')[0], viewModel.User.Split('\\')[1], viewModel.Pass)) { viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Stopping Agent Service")); var service = new ServiceController("Norskale Agent Host Service", viewModel.Host); await Task.Factory.StartNew( () => { if (service.Status != ServiceControllerStatus.Stopped) { service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped); } }); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Killing Agent UI")); await WmiProcess.KillAsync("VUEMUIAgent.exe", viewModel.Host, viewModel.User, viewModel.Pass); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Copy binaries")); await Task.Factory.StartNew( () => DirectoryCopy(viewModel.Path, $@"\\{viewModel.Host}\C$\Program Files (x86)\Norskale\Norskale Agent Host\", true)); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Starting Service")); await Task.Factory.StartNew( () => { service.Start(); service.WaitForStatus(ServiceControllerStatus.Running); }); viewModel.Log.Add(new LogViewModel(LogLevel.Information, "Done")); } }
public void Bill() { var p = WmiProcess.Run("SrvTestWeb01", "ping", "www.google.com", ""); }