[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to recognize that process is running in c #

Posted on 2009-04-06
8
Medium Priority
?
270 Views
Last Modified: 2013-12-17
I am coding with C# and need to know how to prevent my new.exe executable from running if my "current.exe" process is currently running.  For instance, if current.exe is running and I click on my new.exe to run an info message displays and informs that current.exe is currently running, if it is not currently running my new.exe launches.

I know I have to do an if event:

if {current.exe is running} display message
else open up new.exe or return;

thank you
0
Comment
Question by:systems_ax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 6

Expert Comment

by:SaedSalman
ID: 24079112
About 6 lines of code,

here is how to Get a List of Running Processes in C#:
http://www.howtogeek.com/howto/programming/get-a-list-of-running-processes-in-c/

How to get the Process Name in C#
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=17937

C# : Get the all running processes and applications
http://www.eggheadcafe.com/tutorials/aspnet/cb972d77-0892-4bf7-834d-c23b6dd5c03a/c--get-the-all-running.aspx
0
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 2000 total points
ID: 24079124
Try this:
    using System.Diagnostics;
 
    Process aProcess = Process.GetCurrentProcess();
    string aProcName = aProcess.ProcessName;
			
    if (Process.GetProcessesByName(aProcName).Length > 1)
    {
        Application.ExitThread();
    }

Open in new window

0
 
LVL 6

Expert Comment

by:HarryNS
ID: 24079199
System.Diagnostics.Process.GetProcessesByName("Current")
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 1

Author Comment

by:systems_ax
ID: 24079380
thanks,
I have the following anf nothing happens when I run outlook and click on the button that contains the following code: any ideas???

private void button4_Click(object sender, EventArgs e)
        {
            Process OUTLOOK= Process.GetCurrentProcess();
            string aProcName = OUTLOOK.ProcessName;

            if (Process.GetProcessesByName("OUTLOOK.exe").Length > 1)
            {
                MessageBox.Show("Close OUTLOOK first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

0
 
LVL 1

Author Comment

by:systems_ax
ID: 24079481
i fixed it,works great, thanks so much
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24079536
Great! Can you post the fix to your code, for the sake of the solution for others? Thanks.
0
 
LVL 1

Author Comment

by:systems_ax
ID: 24080323
sure, it is:

private void button4_Click(object sender, EventArgs e)
        {
            Process OUTLOOK= Process.GetCurrentProcess();
            string aProcName = OUTLOOK.ProcessName;

            if (Process.GetProcessesByName("OUTLOOK").Length > 0)
            {
                MessageBox.Show("Close OUTLOOK first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
0
 
LVL 1

Author Comment

by:systems_ax
ID: 24080329
i'll be posting another ? about another function I am not familiar with
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question