Home > Software engineering >  How to set the only identification signs of an application?
How to set the only identification signs of an application?

Time:09-22

Two applications, such as A and B are my development, I think after A startup, the enumeration process window or in the memory, find B, then operate it, the question is, how do I know if A process is B?

Someone said, using the window title, but, B version of my progress, title may also be in the future will be different, and possibly, other applications that use the same title as B,

Or, in the name of the file, however, some users, will execute the executable name change again, such as XXX. Exe, changed to XXX. 1.06. Exe, coupled with the version number, in this way, will not be able to identify,

As A result of A and B are my development, can be in B, set up A similar "mutex" such A thing, let A to check it? But really, if use the mutex, can only be detected if the mutex already exist, but don't know, is a process of,

Is there a way to set up the only sign of such an application, for other applications to test?

CodePudding user response:


Memory mapped files, can put data, read other programs

CodePudding user response:

reference 1st floor smwhotjay response:

Memory mapped files, can put data, other applications read


I don't want to share data, I'm going to set up A sign in the program of B, then B after launch, A restart, A enumerated all Windows (process), you can only find B, please note that the execution of the file name and title bar text B, is likely to change,

CodePudding user response:

 # pragma comment (lib, "ole32") 
#include
#include
The union U {
GUID GUID.
Unsigned char b [16].
} u;
int i;
Char s [33];
Void main () {
If (S_OK!=CoCreateGuid (& amp; U.g uid)) return;
for (i=0; i<16. I++) sprintf (s + I * 2, "x % 02," u.b [I]);
Printf (" GUID=% s \ n ", s);//every result is not the same as
}
//GUID=f5a44443aa5fb1479bf6741fa213d33c

CodePudding user response:

Can use named Mutex semaphore CreateMutex name using GUID

CodePudding user response:

reference 4 floor zgl7903 response:
can use named Mutex semaphore CreateMutex name using GUID

But, I'm A program enumerated all window or process, how to know A certain process, exist the Mutex semaphore?

CodePudding user response:

The
reference 3 floor zhao4zhong1 response:
 # pragma comment (lib, "ole32") 
#include
#include
The union U {
GUID GUID.
Unsigned char b [16].
} u;
int i;
Char s [33];
Void main () {
If (S_OK!=CoCreateGuid (& amp; U.g uid)) return;
for (i=0; i<16. I++) sprintf (s + I * 2, "x % 02," u.b [I]);
Printf (" GUID=% s \ n ", s);//every result is not the same as
}
//GUID=f5a44443aa5fb1479bf6741fa213d33c

Zhao four teachers, it is not difficult to generate the unique ID, the key is, how do I enumerate all processes, and then know, in a process is the ID?

CodePudding user response:

reference 5 floor screen12 reply:
Quote: refer to 4th floor zgl7903 response:

Can use named Mutex semaphore CreateMutex name using GUID

But, I'm A program enumerated all window or process, how to know A certain process, exist the Mutex semaphore?


See the MSDN help document CreateMutex GetLastError returns ERROR_ALREADY_EXISTS
 
BOOL IsNamedMutexExit (LPCTSTR szName)
{
BOOL bRet=FALSE;

HANDLE hMutex=CreateMutex (NULL, FALSE, szName);
If (hMutex)
{
If (GetLastError ()==ERROR_ALREADY_EXISTS)
BRet=TRUE;
The CloseHandle (hMutex);
}

Return bRet.
}


CodePudding user response:

refer to 7th floor zgl7903 response:
Quote: refer to fifth floor screen12 response:

Quote: refer to 4th floor zgl7903 response:

Can use named Mutex semaphore CreateMutex name using GUID

But, I'm A program enumerated all window or process, how to know A certain process, exist the Mutex semaphore?


See the MSDN help document CreateMutex GetLastError returns ERROR_ALREADY_EXISTS
 
BOOL IsNamedMutexExit (LPCTSTR szName)
{
BOOL bRet=FALSE;

HANDLE hMutex=CreateMutex (NULL, FALSE, szName);
If (hMutex)
{
If (GetLastError ()==ERROR_ALREADY_EXISTS)
BRet=TRUE;
The CloseHandle (hMutex);
}

Return bRet.
}




This useless ah, this is only to determine whether a mutex exist, however, do not know that it exists in which process,

Or, I don't know the process of a concrete, there is no such a mutex.

CodePudding user response:

ReadProcessMemory

CodePudding user response:

You can broadcast a message, and then the target process window after the message is received, to return to the current process ID or window handle

CodePudding user response:

Create a named kernel object ~

CodePudding user response:

The
refer to 12 floor VisualEleven reply:
create a named kernel object ~


A mutex is also belong to the kernel object? But, I in the process of B creates A named mutex object, then A process of enumeration to A process or A window, how to judge, the process (or window), containing the mutex object?

CodePudding user response:

HANDLE hMutex=CreateMutex (... , "XXXX_XXX");

If (ERROR_ALREADY_EXISTS==GetLastError ()) {printf (" Exist "); }

CodePudding user response:

On the 14th floor VisualEleven
reference response:
HANDLE hMutex=CreateMutex (... , "XXXX_XXX");

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related