Identifying a currently running application
-
Hi! How Windows XP(in general any Windows OS) identifies the currently running VC++ application?
-
Hi! How Windows XP(in general any Windows OS) identifies the currently running VC++ application?
If you want to know the name of Currently running .exe . Use
GetModuleFileName()
See here http://msdn.microsoft.com/en-us/library/ms683197(v=vs.85).aspx -
If you want to know the name of Currently running .exe . Use
GetModuleFileName()
See here http://msdn.microsoft.com/en-us/library/ms683197(v=vs.85).aspxI've created a Single Instance application using the following code:
if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
{
long dwError = ::GetLastError();
if(dwError == ERROR_ALREADY_EXISTS)
// MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB_OK);
EndDialog(NULL,IDOK);
}I've designed one project as a template and used it to build many applications. e.g I tried to run one application named "app2" while another application named "app1" is already running. But "app2" does not run. I don't want this. "app2" should not run if and only if "app2" is already running. Otherwise it has to run normal. How to do this?
-
I've created a Single Instance application using the following code:
if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
{
long dwError = ::GetLastError();
if(dwError == ERROR_ALREADY_EXISTS)
// MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB_OK);
EndDialog(NULL,IDOK);
}I've designed one project as a template and used it to build many applications. e.g I tried to run one application named "app2" while another application named "app1" is already running. But "app2" does not run. I don't want this. "app2" should not run if and only if "app2" is already running. Otherwise it has to run normal. How to do this?
-
I solved the problem patially by following the above link. Now my problem is: If I close one instance the other instance is also closed. How to fix this?
-
I solved the problem patially by following the above link. Now my problem is: If I close one instance the other instance is also closed. How to fix this?
pix_programmer wrote:
If I close one instance the other instance is also closed. How to fix this?
How it is possible ?? Are you using this code in InitInstance.
if (g_SingleInstanceObj.IsAnotherInstanceRunning())
return FALSE;If you are using this code in InitInstance than another instance is not getting created but the running instance is not getting closed. Please share your code.
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)
-
pix_programmer wrote:
If I close one instance the other instance is also closed. How to fix this?
How it is possible ?? Are you using this code in InitInstance.
if (g_SingleInstanceObj.IsAnotherInstanceRunning())
return FALSE;If you are using this code in InitInstance than another instance is not getting created but the running instance is not getting closed. Please share your code.
"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN)
I've not used the above code. I used the following code.
if(NULL != ::CreateMutex(NULL, TRUE,\_T("{AFD2966D-9A83-4E3A-9C9E-CD81E96D819A}"))) { long dwError = ::GetLastError(); if(dwError == ERROR\_ALREADY\_EXISTS) // MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB\_OK); EndDialog(NULL,IDOK);
}
By instance I do not mean same application instance. If I close app1, app2 is also closed. What to do?
-
I've not used the above code. I used the following code.
if(NULL != ::CreateMutex(NULL, TRUE,\_T("{AFD2966D-9A83-4E3A-9C9E-CD81E96D819A}"))) { long dwError = ::GetLastError(); if(dwError == ERROR\_ALREADY\_EXISTS) // MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB\_OK); EndDialog(NULL,IDOK);
}
By instance I do not mean same application instance. If I close app1, app2 is also closed. What to do?
pix_programmer wrote:
If I close app1, app2 is also closed. What to do?
What do you mean app1 and app2?? Are you talking about instance of same application?? If CreateMutex is fail than it returns NULL and you are checking that if it is not null than you are checking GetLastError.
if(NULL == ::CreateMutex(NULL, TRUE,_T("{AFD2966D-9A83-4E3A-9C9E-CD81E96D819A}")))
{
long dwError = ::GetLastError();
if(dwError == ERROR_ALREADY_EXISTS)
{
EndDialog(NULL,IDOK);
return FALSE;
}
}"Every Little Smile can touch Somebody's Heart... May we find Hundreds of Reasons to Smile Everyday... and May WE be the Reason for someone else to smile always!" (ICAN) "Your thoughts are the architects of your destiny."
-
I've created a Single Instance application using the following code:
if(NULL != ::CreateMutex(NULL, TRUE,_T("CSingleInstanceApp")))
{
long dwError = ::GetLastError();
if(dwError == ERROR_ALREADY_EXISTS)
// MessageBox(NULL,L"You are Already Running Application.",L"ERROR!!",MB_OK);
EndDialog(NULL,IDOK);
}I've designed one project as a template and used it to build many applications. e.g I tried to run one application named "app2" while another application named "app1" is already running. But "app2" does not run. I don't want this. "app2" should not run if and only if "app2" is already running. Otherwise it has to run normal. How to do this?
If I read your correctly, the name of mutex should be unique ,pass some unique string while creating first instance of app1,app2 and so on. the reason you are getting problem you are using the same mutex name for all the application. HTH