I am writing a program that continuously checks if rdp is running. If not running than it will send an email notification. Could someone tell me how to code that part which check if mstsc process is running.
using System.Diagnostics;
using System.Net.Mail;
using System.Net;
var from = "[email protected]";
var to = "[email protected]";
var subject = "Test mail";
var body = "Test body";
var username = "[email protected]"; // get from Mailtrap
var password = "password"; // get from Mailtrap
var host = "mailserver";
var port = portnumber;
var client = new SmtpClient(host, port)
{
Credentials = new NetworkCredential(username, password),
EnableSsl = false
};
Process[] processes = Process.GetProcessesByName("mstsc");
int pid = processes[0].Id;
Process pro = Process.GetProcessById(pid);
client.Send(from, to, subject, body);