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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
EhteshamRank #3,979 · 374 reputationPosted Oct 17, 2012, 11:32 PM EDT
using System.Diagnostics;
Process[] processarray = Process.GetProcesses();
foreach(Process p in processarray)
{
Console.WriteLine("Process: {0} ID: {1}", p.ProcessName, p.Id);
}
yokzuRank #5,421 · 300 reputationPosted Oct 18, 2012, 12:30 AM EDT
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.";
}
}
VulpesRank #55 · 29.2K reputationPosted Oct 18, 2012, 12:33 AM EDT