Solved

how to recognize that process is running in c #

Posted on 2009-04-06
8
248 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
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 500 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now