?
Solved

how to recognize that process is running in c #

Posted on 2009-04-06
8
Medium Priority
?
268 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
Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

 
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

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of this video is to provide viewers with basic examples to understand and use pointers 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.
Suggested Courses

752 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