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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Print all the running Applications using C++, win APIs.

Print all the running Applications using C++, win APIs.

Scheduled Pinned Locked Moved C / C++ / MFC
c++
11 Posts 4 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.
  • S Subrat 4708266

    Hi all I need to print all the 'Running Applications' in windows(XP/VISTA) using C++, win APIs. Thanks & Regrads, Subrat

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #2

    Have a look to EnumWindows [^] function. :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
    [My articles]

    In testa che avete, signor di Ceprano?

    S 1 Reply Last reply
    0
    • CPalliniC CPallini

      Have a look to EnumWindows [^] function. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      S Offline
      S Offline
      Subrat 4708266
      wrote on last edited by
      #3

      I am using vs 2005.I need native c++ code to perform the same task. It'd be great if your are telling me how to implement that CALLBACK func which is used in EnumWindows() API.

      CPalliniC 1 Reply Last reply
      0
      • S Subrat 4708266

        I am using vs 2005.I need native c++ code to perform the same task. It'd be great if your are telling me how to implement that CALLBACK func which is used in EnumWindows() API.

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #4

        Implementing the callback isn't difficult. Anyway, to fullfill your requirements, maybe this example [^] is more appropriate. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        In testa che avete, signor di Ceprano?

        S 1 Reply Last reply
        0
        • CPalliniC CPallini

          Implementing the callback isn't difficult. Anyway, to fullfill your requirements, maybe this example [^] is more appropriate. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          S Offline
          S Offline
          Subrat 4708266
          wrote on last edited by
          #5

          Thanks a lot for you quick response. This exmple is for enumurating all processes.I need only Applications those are are displyed in Task Manager->Application tab.

          1 Reply Last reply
          0
          • S Subrat 4708266

            Hi all I need to print all the 'Running Applications' in windows(XP/VISTA) using C++, win APIs. Thanks & Regrads, Subrat

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #6

            You could use the tool help library:

            #include <Tlhelp32.h>
            ...

            HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS\_SNAPPROCESS, 0);
            if (INVALID\_HANDLE\_VALUE != hProcessSnapshot)
            {
            	PROCESSENTRY32 processentry;
            	processentry.dwSize = sizeof(PROCESSENTRY32);
            	if (::Process32First(hProcessSnapshot, &processentry))
            	{
            		do
            		{
            			// do something with the info in processentry
            
            			TRACE("%S\\n", processentry.szExeFile);
            		}
            		while (::Process32Next(hProcessSnapshot, &processentry));
            	}
            	::CloseHandle(hProcessSnapshot);
            }
            

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            S 2 Replies Last reply
            0
            • M Mark Salsbery

              You could use the tool help library:

              #include <Tlhelp32.h>
              ...

              HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS\_SNAPPROCESS, 0);
              if (INVALID\_HANDLE\_VALUE != hProcessSnapshot)
              {
              	PROCESSENTRY32 processentry;
              	processentry.dwSize = sizeof(PROCESSENTRY32);
              	if (::Process32First(hProcessSnapshot, &processentry))
              	{
              		do
              		{
              			// do something with the info in processentry
              
              			TRACE("%S\\n", processentry.szExeFile);
              		}
              		while (::Process32Next(hProcessSnapshot, &processentry));
              	}
              	::CloseHandle(hProcessSnapshot);
              }
              

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              S Offline
              S Offline
              Subrat 4708266
              wrote on last edited by
              #7

              I got the soln.Now problem is I want to store all app names inside a container(Vector).And finally calling a function to print it.But that function is unable to print these application names correctly. #include "vector" using namespace std; wchar_t szText[256];//Holds app name //Print function void PrintText(vector<wchar_t*> apps) { for (vector<wchar_t*> ::iterator itr = apps.begin(); itr != apps.end(); ++itr) { wprintf(L"%s \n", *itr); } } vector<wchar_t*> r_apps; //Inside callback func bool callbackfn(.....) { ...... ...... ...... // if printing szText using wprintf() it is printing the app names correctly. //using vector to store all these app names r_apps.push_back (szText); } //Main func int _tmain(int argc, _TCHAR* argv[]) { ....... ....... PrintText(r_apps); return 0; } PrintText() is unable to print the app names correctly. My o/p comes like below: ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? // If using wprintf() above 'r_apps.push_back (szText);' statement then o/p come like belows. C:\WINDOWS\System32\cmd.exe AppPrint - Microsoft Visual Studio CodeProject: Visual C++ / MFC Discussion Boards. Free source code and programmin g help - Mozilla Firefox Registry Mechanic ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? Please help me in this regard.

              M 1 Reply Last reply
              0
              • S Subrat 4708266

                I got the soln.Now problem is I want to store all app names inside a container(Vector).And finally calling a function to print it.But that function is unable to print these application names correctly. #include "vector" using namespace std; wchar_t szText[256];//Holds app name //Print function void PrintText(vector<wchar_t*> apps) { for (vector<wchar_t*> ::iterator itr = apps.begin(); itr != apps.end(); ++itr) { wprintf(L"%s \n", *itr); } } vector<wchar_t*> r_apps; //Inside callback func bool callbackfn(.....) { ...... ...... ...... // if printing szText using wprintf() it is printing the app names correctly. //using vector to store all these app names r_apps.push_back (szText); } //Main func int _tmain(int argc, _TCHAR* argv[]) { ....... ....... PrintText(r_apps); return 0; } PrintText() is unable to print the app names correctly. My o/p comes like below: ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? // If using wprintf() above 'r_apps.push_back (szText);' statement then o/p come like belows. C:\WINDOWS\System32\cmd.exe AppPrint - Microsoft Visual Studio CodeProject: Visual C++ / MFC Discussion Boards. Free source code and programmin g help - Mozilla Firefox Registry Mechanic ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? ?????????????????????????↕?A?↕?A?↕?↕?????????????????????????? Please help me in this regard.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #8

                I can't tell what you're doing in that code, but it looks like you're adding the same wchar_t* to the vector every time, and there's no valid string data being pointed to. If you're going to store wchar_t pointers in the vector, then you need to allocate a separate buffer for each string and copy each string's contents into the new buffers.

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                1 Reply Last reply
                0
                • S Subrat 4708266

                  Hi all I need to print all the 'Running Applications' in windows(XP/VISTA) using C++, win APIs. Thanks & Regrads, Subrat

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #9

                  This[^] is helpful for you.

                  1 Reply Last reply
                  0
                  • M Mark Salsbery

                    You could use the tool help library:

                    #include <Tlhelp32.h>
                    ...

                    HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS\_SNAPPROCESS, 0);
                    if (INVALID\_HANDLE\_VALUE != hProcessSnapshot)
                    {
                    	PROCESSENTRY32 processentry;
                    	processentry.dwSize = sizeof(PROCESSENTRY32);
                    	if (::Process32First(hProcessSnapshot, &processentry))
                    	{
                    		do
                    		{
                    			// do something with the info in processentry
                    
                    			TRACE("%S\\n", processentry.szExeFile);
                    		}
                    		while (::Process32Next(hProcessSnapshot, &processentry));
                    	}
                    	::CloseHandle(hProcessSnapshot);
                    }
                    

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    S Offline
                    S Offline
                    Subrat 4708266
                    wrote on last edited by
                    #10

                    This program will display all the running processes but not the application names those are displayed by Task Manager->Application. Another q. is to use TRACE what header I will have to include.

                    M 1 Reply Last reply
                    0
                    • S Subrat 4708266

                      This program will display all the running processes but not the application names those are displayed by Task Manager->Application. Another q. is to use TRACE what header I will have to include.

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #11

                      A search ffor "list running processes" yields lots of info. For example: this one[^]

                      Member 4708266 wrote:

                      to use TRACE what header I will have to include.

                      Diagnostic Services (MFC)[^] I just used that as a test example - you'll probably need to output to someplace more useful. Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      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