Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Single Instance restriction

Single Instance restriction

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr Bose Dayala
    wrote on last edited by
    #1

    Hi, From my application I am launchin another exe by calling thrugh WinExec("EXE path",SW_SHOW).But the problem here is EXE is getting opened every time when I click the toolbar butto.I want to restrict this for single instance. can anybody help me regarding this? Bose Dayala

    M 1 Reply Last reply
    0
    • M Mr Bose Dayala

      Hi, From my application I am launchin another exe by calling thrugh WinExec("EXE path",SW_SHOW).But the problem here is EXE is getting opened every time when I click the toolbar butto.I want to restrict this for single instance. can anybody help me regarding this? Bose Dayala

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      the exe you are launching do u have its code, if you do you can code in to the exe itself that it will run only one time every time it start it can do a FindWindow(windowname) if exists exit ( or Win32 Events can be used ) if you don't have access to the exe's code than in the launching application use CreateProcess instead of winexec and use the handle to the process too determine if the exe is running or not hope it helps :) C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

      M 1 Reply Last reply
      0
      • M Monty2

        the exe you are launching do u have its code, if you do you can code in to the exe itself that it will run only one time every time it start it can do a FindWindow(windowname) if exists exit ( or Win32 Events can be used ) if you don't have access to the exe's code than in the launching application use CreateProcess instead of winexec and use the handle to the process too determine if the exe is running or not hope it helps :) C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg

        M Offline
        M Offline
        Mr Bose Dayala
        wrote on last edited by
        #3

        Hi, thnx for quick help....I don't have its code and even ProcessID...how to get the process ID for any EXE?? thnx and regards Bose Dayala. ThomasKennedyBose

        J 2 Replies Last reply
        0
        • M Mr Bose Dayala

          Hi, thnx for quick help....I don't have its code and even ProcessID...how to get the process ID for any EXE?? thnx and regards Bose Dayala. ThomasKennedyBose

          J Offline
          J Offline
          Jitendra gangwar
          wrote on last edited by
          #4

          Task Manager is an example of a program that enumerates all running processes. It is implemented using data from the performance registry. The following sample code uses the EnumProcesses function to enumerate the current processes in the system. This method is easier than using the performance registry. #include #include #include "psapi.h" void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if ( hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } } // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } The main function obtains a list of processes by using the EnumProcesses function. For each process, main calls the PrintProcessNameAndID function, passing it the process identifier. PrintProcessNameAndID in turn calls the OpenProcess function to obtain the process handle. If OpenProcess fails, the output shows only the process identifier. For example, OpenProcess fails for the Idle and CSRSS processes because their access restrictions prevent user-level code from opening them. Next, PrintProcessNameAndID calls the EnumProcessModules function to obtain the module handles. Finally, PrintProcessNameAndID calls the GetModuleBaseName function to obtain the name of the executable file. This may help u. /jitendra :laugh: Jitendra Pal Singh Gangwar E-mail: jitendra_gangwar@hotmail.com Mobile No: 09831352305

          1 Reply Last reply
          0
          • M Mr Bose Dayala

            Hi, thnx for quick help....I don't have its code and even ProcessID...how to get the process ID for any EXE?? thnx and regards Bose Dayala. ThomasKennedyBose

            J Offline
            J Offline
            Jitendra gangwar
            wrote on last edited by
            #5

            Task Manager is an example of a program that enumerates all running processes. It is implemented using data from the performance registry. The following sample code uses the EnumProcesses function to enumerate the current processes in the system. This method is easier than using the performance registry. #include #include #include "psapi.h" void PrintProcessNameAndID( DWORD processID ) { char szProcessName[MAX_PATH] = "unknown"; // Get a handle to the process. HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID ); // Get the process name. if ( hProcess ) { HMODULE hMod; DWORD cbNeeded; if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ) { GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName) ); } } // Print the process name and identifier. printf( "%s (Process ID: %u)\n", szProcessName, processID ); CloseHandle( hProcess ); } void main( ) { // Get the list of process identifiers. DWORD aProcesses[1024], cbNeeded, cProcesses; unsigned int i; if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) return; // Calculate how many process identifiers were returned. cProcesses = cbNeeded / sizeof(DWORD); // Print the name and process identifier for each process. for ( i = 0; i < cProcesses; i++ ) PrintProcessNameAndID( aProcesses[i] ); } The main function obtains a list of processes by using the EnumProcesses function. For each process, main calls the PrintProcessNameAndID function, passing it the process identifier. PrintProcessNameAndID in turn calls the OpenProcess function to obtain the process handle. If OpenProcess fails, the output shows only the process identifier. For example, OpenProcess fails for the Idle and CSRSS processes because their access restrictions prevent user-level code from opening them. Next, PrintProcessNameAndID calls the EnumProcessModules function to obtain the module handles. Finally, PrintProcessNameAndID calls the GetModuleBaseName function to obtain the name of the executable file. This may help u. /jitendra :laugh:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups