public static void Main(string[] args) { string command = "start"; if (args.Length > 0) { command = args[0]; } do { qconf = new QuikConfiguration(); //Console.Clear(); switch (command.ToLower()) { case "setup": Setup(); break; case "restart": KillQuik(); StartQuik(); break; case "stop": KillQuik(); break; case "start": StartQuik(); break; case "exit": case "quit": return; default: break; } Console.WriteLine(@"Available commands: 'start', 'stop', 'restart', 'setup', 'exit'"); command = Console.ReadLine().Trim().ToLower(); } while (true); }
public static void KillQuik() { ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = configFile; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); qconf = (QuikConfiguration)config.GetSection("QuikConfiguration"); if (qconf == null) { Main(new string[] { "-setup" }); return; } Console.WriteLine(@"Closing running processes of '" + qconf.QuikPath + "', if present."); var Quiks = Process.GetProcessesByName("info"); var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process"; using (var searcher = new ManagementObjectSearcher(wmiQueryString)) using (var results = searcher.Get()) { var ps = from p in Quiks join mo in results.Cast <ManagementObject>() on p.Id equals(int)(uint) mo["ProcessId"] //where (string)mo["ExecutablePath"] == qconf.QuikPath select new { Process = p, Path = (string)mo["ExecutablePath"], CommandLine = (string)mo["CommandLine"], }; foreach (var p in ps) { p.Process.Kill(); } } }
public static void StartQuik() { ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = configFile; Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); qconf = (QuikConfiguration)config.GetSection("QuikConfiguration"); if (qconf == null) { Main(new string[] { "-setup" }); return; } Console.WriteLine(@"Starting '" + qconf.QuikPath + "'."); // From MSDN: Key containers provide the most secure way to persist cryptographic keys // and keep them secret from malicious third parties. string containerName = qconf.Name.GetStringHash(); string salt = MachineIdentificator.GetUniqueStringID(); var RSAProvider = RsaUtilities.GetRSAProviderFromContainer(containerName + salt, false); //Decrupt sensitive parts qconf.User = Encoding.UTF8.GetString(RSAProvider.Decrypt(Convert.FromBase64String(qconf.User), false)); qconf.Password = Encoding.UTF8.GetString(RSAProvider.Decrypt(Convert.FromBase64String(qconf.Password), false)); StartProcessAndSendKeys(); //Console.WriteLine(qconf.Name); //Console.WriteLine(qconf.QuikPath); //Console.WriteLine(qconf.User); //Console.WriteLine(qconf.Password); }