Hi
I want to check an .exe program (for example notepad.exe) every 5 minute (with timers) and if this .exe is not running, I want to run this .exe program. How may I do that?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Oct 18, 2012, 4:33 AM
yokzuPosted Oct 18, 2012, 4:30 AM
I find some codes form google and it is controlling "notepad.exe" and it is working correctly. But When I try to check another .exe console program, it is not working. Are there any difference between .exe's?
public bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
private void timer1_Tick(object sender, EventArgs e)
{
Process thisProc = Process.GetCurrentProcess();
if (IsProcessOpen("notepad") == false)
{
textBox1.Text = "Program starting";
Process islem = new Process();
islem.StartInfo.FileName = "C:\\Windows\\system32\\notepad.exe";
islem.Start();
}
else
{
textBox1.Text="Program running.";
}
}
EhteshamPosted Oct 18, 2012, 3:32 AM
using System.Diagnostics;
Process[] processarray = Process.GetProcesses();
foreach(Process p in processarray)
{
Console.WriteLine("Process: {0} ID: {1}", p.ProcessName, p.Id);
}