Detecting that a program is already running
Messages   Related Types
This message was discovered on microsoft.public.dotnet.general.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Joecx
Hi
Does anyone have the code or maybe give me a start on how to detect if my
program is already running if someone tries to run it again while it's already
running? I know I could do this with a dummy file by putting something in the
file while it's running and emptying the file when it's not running, but I was
hoping for something a little more professional. Has anyone done this yet?

Joe
Reply to this message...
 
    
Raghavendra T V
Hi Joe,

You can try this code

' Imports System.Diagnostics.

Dim p As Process
For Each p In Process.GetProcesses
lstProcesses.Items.Add(p)
Next

you get a list of process running in the machine may be you can check your
program in the list of process and
if its there then its running else not !

Hope this helps you

Thanks
Raghavendra

"Joecx" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
ToddT
in the past, i have used the win32 findwindow api to do this. i wonder
if there is a .net solution...

On Thu, 26 Aug 2004 19:52:05 +0530, "Raghavendra T V"
<Click here to reveal e-mail address> wrote:

[Original message clipped]

Reply to this message...
 
    
Jon Skeet [C# MVP] (VIP)
Joecx <Click here to reveal e-mail address> wrote:
[Original message clipped]

See http://www.pobox.com/~skeet/csharp/faq#one.applications.instance

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
 
    
The Devil
In VB6 I used:

http://internettrash.com/users/fdb/already.htm

If App.PrevInstance = True Then
MsgBox("The program is already running!")
End
End If

Maybe there's an equivalent in c#

Jon Skeet [C# MVP] wrote:

[Original message clipped]

--
incognito http://kentpsychedelic.blogspot.com
new material added 9/5
Reply to this message...
 
    
The Devil
Ok, wait.

I guess this guy has the answer:
http://www.dotnetspider.com/Technology/KBPages/631.aspx

7> Now Paste the following snippet right after the Main functions
starts before the existing line.

Process aProcess = Process.GetCurrentProcess();
string aProcName = aProcess.ProcessName;

if (Process.GetProcessesByName(aProcName).Length > 1)
{
MessageBox.Show("The application is already
running!!","Test",MessageBoxButtons.OK,MessageBoxIcon.Stop);
Application.ExitThread();
}

The Devil wrote:

[Original message clipped]

--
incognito http://kentpsychedelic.blogspot.com
new material added 9/5
Reply to this message...
 
    
Jon Skeet [C# MVP] (VIP)
The Devil <Click here to reveal e-mail address> wrote:
[Original message clipped]

That's not a terribly *good* answer though - it fails if anyone happens
to use the same process name. I gave you a link to a better answer in
my previous post though.

--
Jon Skeet - <Click here to reveal e-mail address>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Reply to this message...
 
 
System.Diagnostics.Process
System.Windows.Forms.Application
System.Windows.Forms.MessageBox
System.Windows.Forms.MessageBoxButtons
System.Windows.Forms.MessageBoxIcon




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com