.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification