private void btnFixLogin_Click(object sender, EventArgs e)
{
var lines = File.ReadAllLines("listprocess.txt").Where(arg => !string.IsNullOrWhiteSpace(arg));
var listProcess = Process.GetProcesses().Where(x => lines.Contains(x.ProcessName.ToLower())).ToList();
if (listProcess.Count == 0) {
MessageBox.Show("Wrong config.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
RetartListProcess(listProcess);
}
private void RetartListProcess(List<Process> listProcess)
{
foreach (var process in listProcess)
{
var idprocess = process.Id;
var fullname = GetMainModuleFilepath(idprocess);
process.Kill();
process.WaitForExit();
Process.Start(fullname);
Thread.Sleep(100);
}
}
private string GetMainModuleFilepath(int processId)
{
string wmiQueryString = "SELECT ProcessId, ExecutablePath FROM Win32_Process WHERE ProcessId = " + processId;
using (var searcher = new ManagementObjectSearcher(wmiQueryString))
{
using (var results = searcher.Get())
{
ManagementObject mo = results.Cast<ManagementObject>().FirstOrDefault();
if (mo != null)
{
return (string)mo["ExecutablePath"];
}
}
}
return null;
}