public static string processCustomizedCommand(CommandType ct) { if (ct.Command == null) { return "Not implemented yet."; } Process process = new Process(); string output = null; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.ErrorDialog = false; process.StartInfo.FileName = "cmd"; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.Arguments = "/c " + "\"" + (ct.Path == null ? (ct.Command.Contains(" ") ? "\"" + ct.Command + "\"" : ct.Command) : "\"" + ct.Path + "\\" + ct.Command + "\"") + (ct.Parameters == null ? null : " \"" + ct.Parameters + "\"") + "\""; process.EnableRaisingEvents = false; try { process.Start(); output += process.StandardOutput.ReadToEnd(); process.WaitForExit(); process.Close(); } catch (Exception ex) { output = ex.ToString(); } return output; }
private static string getNetworking() { string output = null; CommandType ct = new CommandType("netstat.exe"); output = ProcessCustomizedCommand.processCustomizedCommand(ct); ct = new CommandType("netstat.exe", "-e"); output += ProcessCustomizedCommand.processCustomizedCommand(ct); return output; }
public string processCommand(CommandType command) { // Run predefiend commands if (command.Path != null && command.Path.CompareTo(PredefinedCommands.ProcessPredefinedCommand.prefixOfPredefinedCommand) == 0) { return PredefinedCommands.ProcessPredefinedCommand.processPredefinedCommands(command.Command); } // Run customized commands else { return CustomizedCommands.ProcessCustomizedCommand.processCustomizedCommand(command); } }
private static string getServices() { CommandType ct = new CommandType("net.exe", "start"); return ProcessCustomizedCommand.processCustomizedCommand(ct); }