Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:43:51+00:00 2026-05-16T08:43:51+00:00

Quoted from here : BOOL WINAPI CreateProcess( __in_opt LPCTSTR lpApplicationName, __inout_opt LPTSTR lpCommandLine, __in_opt

  • 0

Quoted from here:

BOOL WINAPI CreateProcess(
  __in_opt     LPCTSTR lpApplicationName,
  __inout_opt  LPTSTR lpCommandLine,
  __in_opt     LPSECURITY_ATTRIBUTES lpProcessAttributes,
  __in_opt     LPSECURITY_ATTRIBUTES lpThreadAttributes,
  __in         BOOL bInheritHandles,
  __in         DWORD dwCreationFlags,
  __in_opt     LPVOID lpEnvironment,
  __in_opt     LPCTSTR lpCurrentDirectory,
  __in         LPSTARTUPINFO lpStartupInfo,
  __out        LPPROCESS_INFORMATION lpProcessInformation
);

I have two independant programe that creates exactly the same process, how can I ensure that if one of them has already created the process, the other won’t create it twice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:43:52+00:00Added an answer on May 16, 2026 at 8:43 am

    The most simple way is if you create a named object after the start of the program. For example CreateEvent, CreateMutex and so on. To verify existance of the application you can just use OpenEvent, OpenMutex and so on before creating of the object. You can choose (if desired) the name of the object with the the “Global\” prefix (see http://msdn.microsoft.com/en-us/library/aa382954.aspx) to allow only one process for all terminal server session.

    UPDATED: Because how I can see there are different opinions about my suggestion I try to explain it more exactly and add the corresponding test example.

    The main idea is that the application which are started create any named object is the object with the same name not yet exist. This only reserve the name in the Kernel Object Namespaces. No real usage of the object are needed. The advantaged of this way compared with creating of a file on the disk is that named objects are temporary and are owned by a application. So if the application are ended, be killed or be terminated in any other way (because of unhanded exception for example) the named object will be automatically deleted by the operation system. In the following example I don’t use CloseHandle at all. How you can test the application can successfully determine whether it runs as the first instance or not.

    #include <windows.h>
    //#include <Sddl.h>
    
    LPCTSTR g_pszEventName = TEXT("MyTestEvent"); // TEXT("Global\\MyTestEvent")
    
    void DisplayFirstInstanceStartedMessage()
    {
        TCHAR szText[1024];
        wsprintf (szText,
            TEXT("The first instance are started.\nThe event with the name \"%s\" is created."),
            g_pszEventName);
    
        MessageBox (NULL,
            szText,
            TEXT("CreateEventTest"), MB_OK);
    }
    
    void DisplayAlreadyRunningMessage ()
    {
        TCHAR szText[1024];
        wsprintf (szText,
            TEXT("The first instance of the aplication is already running.\nThe event with the name \"%s\" already exist."),
            g_pszEventName);
    
        MessageBox (NULL,
            szText,
            TEXT("CreateEventTest"), MB_ICONWARNING | MB_OK);
    }
    
    void DisplayErrorMessage (DWORD dwErrorCode)
    {
        if (dwErrorCode == ERROR_ALREADY_EXISTS)
            DisplayAlreadyRunningMessage();
        else {
            LPTSTR  pErrorString;
            if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM |    // Always search in system message table !!!
                                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                                FORMAT_MESSAGE_IGNORE_INSERTS |
                                0, NULL,                // source of message definition
                                dwErrorCode,            // message ID
        //                        0,                      // language ID
        //                        GetUserDefaultLangID(), // language ID
        //                        GetSystemDefaultLangID(),
                                MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
                                (LPTSTR)&pErrorString,   // pointer for buffer to allocate
                                0,                      // min number of chars to allocate
                                NULL)) {
                MessageBox (NULL, pErrorString, TEXT("CreateEventTest"), MB_OK);
                LocalFree (pErrorString);
            }
            else {
                TCHAR szText[1024];
                wsprintf (szText, TEXT("Error %d in the CreateEvent(..., \"%s\")"), dwErrorCode, g_pszEventName);
                MessageBox (NULL, szText, TEXT("CreateEventTest"), MB_OK);
            }
        }
    }
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
        //SECURITY_ATTRIBUTES sa;
        //BOOL bSuccess;
        HANDLE hEvent = OpenEvent (EVENT_MODIFY_STATE, FALSE, g_pszEventName);// EVENT_ALL_ACCESS
        if (hEvent == NULL) {
            DWORD dwErrorCode = GetLastError();
            if (dwErrorCode != ERROR_FILE_NOT_FOUND) {
                DisplayErrorMessage(dwErrorCode);
                return 1;
            }
        }
        else {
            DisplayAlreadyRunningMessage();
            return 0;
        }
    
        //sa.bInheritHandle = FALSE;
        //sa.nLength = sizeof(SECURITY_ATTRIBUTES);
        //bSuccess = ConvertStringSecurityDescriptorToSecurityDescriptor (
        //    TEXT("D:(A;OICI;GA;;;WD)"),    // Allow full control 
        //    SDDL_REVISION_1,
        //    &sa.lpSecurityDescriptor,
        //    NULL);
        hEvent = CreateEvent (NULL, // &sa
            TRUE, FALSE, g_pszEventName);
        //sa.lpSecurityDescriptor = LocalFree (sa.lpSecurityDescriptor);
        if (hEvent == NULL) {
            DWORD dwErrorCode = GetLastError();
            DisplayErrorMessage(dwErrorCode);
            return 1;
        }
        else
            DisplayFirstInstanceStartedMessage();
    
        return 0;
        UNREFERENCED_PARAMETER (hInstance);
        UNREFERENCED_PARAMETER (hPrevInstance);
        UNREFERENCED_PARAMETER (lpCmdLine);
        UNREFERENCED_PARAMETER (nShowCmd);
    }
    

    If one want support that different users from the same desktop or from the different desktops could start only one instance of the program, one can uncomment some parts of the commented code or replace the name MyTestEvent of the event to Global\MyTestEvent.

    I hope after the example my position will be clear. In such kind of the event usage no call of WaitForSingleObject() are needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quoted from here : If delimiter contains a value that is not contained in
Here is some code quoted from Douglas.E.Comer's < Computer Networks and Internets > 4th
Quoted from here : my $result = FormValidator::Simple->check( $query => [ param1 => ['NOT_BLANK',
The below is quoted from here : <?php $directory = dirname(__FILE__).'/locale'; $domain = 'mydomain';
Quoted from here : Security may also be impacted by a characteristic of several
Can someone please tell me how to do this in C#? Convert from Quoted
I found the quoted text in Programming Python 3rd edition by Mark Lutz from
Here is my code: - (BOOL) saveSiteData { // validate all fields if(txtSiteID.text.length ==
Here's the issue, I launch my app from Xcode and it gets up and
Quoted from ngx_hash.c : ngx_strlow(elt->name, names[n].key.data, names[n].key.len); Which copies the lower case string to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.