473,395 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Running processes

Hi,

I have written a win32 console application(exname1.exe) which runs for
ten minutes.I am calling this exname1.exe from another exe named
exname.exe using shellexecuteex.Now from exname.exe coding i have to
check whether exname1.exe is already running or not.How to find whether
a win32 console application is already runing or not from another win32
console application.I need only one copy of exe has to run(for that i
have already used createmutex in exename1.exe.But now i want to know
from exname.exe whether exename1.exe is running or not).How to find all
the processes or particular exe running in the computer using vc++6.0

Regards,
Mani

Mar 23 '06 #1
5 1652
> Hi,

I have written a win32 console application(exname1.exe) which runs for
ten minutes.I am calling this exname1.exe from another exe named
exname.exe using shellexecuteex.Now from exname.exe coding i have to
check whether exname1.exe is already running or not.How to find whether
a win32 console application is already runing or not from another win32
console application.I need only one copy of exe has to run(for that i
have already used createmutex in exename1.exe.But now i want to know
from exname.exe whether exename1.exe is running or not).How to find all
the processes or particular exe running in the computer using vc++6.0


If exe1 already has a mutex, you can simply check in the other exe if it is
running or not. call CreateMutex in your other exe and check the error code.
From MSDN:

"If the mutex is a named mutex and the object existed before this function
call, the return value is a handle to the existing object, GetLastError
returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling
thread is not granted owernship. "

This will tell you if the mutex already exists or not. Hence you know if the
exe1 is running or not. Remebmber to close the mutex handle afterwards.

A general way of checking if a process is running (using win32) would be to
use the Process Status API (PSAPI). Check this:
http://msdn.microsoft.com/library/de..._processes.asp
For more details.

If you were using .NET you would use the Process class for that.

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 23 '06 #2

"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:83**********************************@microsof t.com...
Hi,

I have written a win32 console application(exname1.exe) which runs for
ten minutes.I am calling this exname1.exe from another exe named
exname.exe using shellexecuteex.Now from exname.exe coding i have to
check whether exname1.exe is already running or not.How to find whether
a win32 console application is already runing or not from another win32
console application.I need only one copy of exe has to run(for that i
have already used createmutex in exename1.exe.But now i want to know
from exname.exe whether exename1.exe is running or not).How to find all
the processes or particular exe running in the computer using vc++6.0
If exe1 already has a mutex, you can simply check in the other exe if it
is
running or not. call CreateMutex in your other exe and check the error
code.
From MSDN:


Except you should use OpenMutex instead, because you don't want to exclude
exe1 from starting.

http://msdn.microsoft.com/library/de.../openmutex.asp

Return Values
If the function succeeds, the return value is a handle to the mutex object.

If the function fails, the return value is NULL. To get extended error
information, call GetLastError.

If a named mutex does not exist, the function fails and GetLastError returns
ERROR_FILE_NOT_FOUND.


"If the mutex is a named mutex and the object existed before this function
call, the return value is a handle to the existing object, GetLastError
returns ERROR_ALREADY_EXISTS, bInitialOwner is ignored, and the calling
thread is not granted owernship. "

This will tell you if the mutex already exists or not. Hence you know if
the
exe1 is running or not. Remebmber to close the mutex handle afterwards.

A general way of checking if a process is running (using win32) would be
to
use the Process Status API (PSAPI). Check this:
http://msdn.microsoft.com/library/de..._processes.asp
For more details.

If you were using .NET you would use the Process class for that.

--

Kind regards,
Bruno.
br**********************@hotmail.com
Remove only "_nos_pam"

Mar 23 '06 #3
Ben Voigt wrote:
"Bruno van Dooren" <br**********************@hotmail.com> wrote in message
news:83**********************************@microsof t.com...
If exe1 already has a mutex, you can simply check in the other exe if it
is
running or not. call CreateMutex in your other exe and check the error
code.


Except you should use OpenMutex instead, because you don't want to exclude
exe1 from starting.


But if OpenMutex fails you should CreateMutex, right? But then there
might arise situation when both processes call OpenMutex, concludes that
there isn't one, then both call CreateMutex. To address this you must
finally check with the GetLastError after CreateMutex. That means that
OpenMutex is an extra call that achieves nothing.

CreateMutex doesn't automatically grants you ownership of the mutex.
Waiting functions do that (WaitForSingleObject et al.).
Mar 23 '06 #4
"Mihajlo Cvetanović" <ma*@RnEeMtOsVeEt.co.yu> wrote in message
news:Ob**************@TK2MSFTNGP14.phx.gbl...
Ben Voigt wrote:
"Bruno van Dooren" <br**********************@hotmail.com> wrote in
message news:83**********************************@microsof t.com...
If exe1 already has a mutex, you can simply check in the other exe if it
is
running or not. call CreateMutex in your other exe and check the error
code.


Except you should use OpenMutex instead, because you don't want to
exclude exe1 from starting.


But if OpenMutex fails you should CreateMutex, right? But then there might
arise situation when both processes call OpenMutex, concludes that there
isn't one, then both call CreateMutex. To address this you must finally
check with the GetLastError after CreateMutex. That means that OpenMutex
is an extra call that achieves nothing.

CreateMutex doesn't automatically grants you ownership of the mutex.
Waiting functions do that (WaitForSingleObject et al.).


The OP has already done that in his singleton application. Now he's asking
the question, is it possible to detect whether that application is running
from another application, and for that purpose he should use OpenMutex only.
Mar 23 '06 #5
> The OP has already done that in his singleton application. Now he's
asking the question, is it possible to detect whether that application is
running from another application, and for that purpose he should use
OpenMutex only.


Not true.
For the exe of which only 1 instance may be running (exe) it doesn't matter
if the mutext exists or not.
It just wants ownership. It tries to take it and bails out if it can't.

The managing app (exe1) only want to know if the mutex exists or not.
CreateMutex can achieve
the same thing as OpenMutex, as long as the InitialOwner parameter of
CreateMutex is set to 0, so
that it is not accidently owned.

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Mar 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christopher Attard | last post by:
Hi, I'm using the PerformanceCounter .NET class to obtain the "% Processor Time" for processes that are running on a remote host. These processes are obtained using the...
1
by: Leonid | last post by:
Hello, How to get the list of running processes in VC++ (Similar to Task Manager->Processes window) Regards Leonid
1
by: Jason E. Trout | last post by:
I wrote an applicaion in VB.NET that executes a process in the background using the System.Diagnostics namespace. It peforms as expected as an application. I rewrote the code into a Windows Service...
2
by: Mark | last post by:
I am trying to enumerate the list of running processes on the PocketPC platform. Normally I would just use System.Diagnostics.Process.GetProcesses() and go through the returned Process array, but...
2
by: chris.tice | last post by:
Hi, I am looking for an easy way to find the total number of running processes on a given machine in a C program. Currently I am doing this: system("ps -e | wc -l > count.txt"); then...
2
by: Steve | last post by:
Hi, I'm trying to design a web server where users can login, initiate long running processes on uploaded files, monitor the progress via a web page and download some results when the process has...
0
by: Arkadiusz Miskiewicz | last post by:
Hi, I'm looking for a library (or utility) written in python that would allow me to easily access all possible information about currently running processes (under Linux). Something like...
5
by: garyusenet | last post by:
Hello. I have two programmes both a couple of years old but not .net. One is a DOS based programme and one is a C++ programme. They both run under windows. I would like to write a programme...
1
by: walterbyrd | last post by:
I understand that Python has them, but PHP doesn't. I think that is because mod_php is built into apache, but mod_python is not usually in apache. If mod_python was built into apache, would...
4
by: commander_coder | last post by:
Hello, I write a lot of CGI scripts, in Python of course. Now I need to convert some to long-running processes. I'm having trouble finding resources about the best practices to do that. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.