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. Spawning another application

Spawning another application

Scheduled Pinned Locked Moved C / C++ / MFC
questioncareer
10 Posts 7 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.
  • C Offline
    C Offline
    CoY0te
    wrote on last edited by
    #1

    Pretty simple - I use: ShellExecute() to spawn another application. I use this function because it allows me to specify the directory for spawned application. Now I need to wait for the application to terminate (In fact i would like to spawn it in synchronous mode because I just want to spawn it and wait for it's termination. Is there any function that allows me to check if the application is still running using the HINSTANCE returned by ShellExecute? Or perhaps there is another, easy way to spawn an application in synchronous mode, that does not need any loops checking application's state? (that will eliminate senseless processor usage). Thanks in advance for any suggestions. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

    T R J 3 Replies Last reply
    0
    • C CoY0te

      Pretty simple - I use: ShellExecute() to spawn another application. I use this function because it allows me to specify the directory for spawned application. Now I need to wait for the application to terminate (In fact i would like to spawn it in synchronous mode because I just want to spawn it and wait for it's termination. Is there any function that allows me to check if the application is still running using the HINSTANCE returned by ShellExecute? Or perhaps there is another, easy way to spawn an application in synchronous mode, that does not need any loops checking application's state? (that will eliminate senseless processor usage). Thanks in advance for any suggestions. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Use ShellExecuteEx. It gives you back the handle of spawned process, ready to use with WaitForSingleObject. Tomasz Sowinski -- http://www.shooltz.com

      What is "scratch" and why can everything be made from it?

      C 1 Reply Last reply
      0
      • C CoY0te

        Pretty simple - I use: ShellExecute() to spawn another application. I use this function because it allows me to specify the directory for spawned application. Now I need to wait for the application to terminate (In fact i would like to spawn it in synchronous mode because I just want to spawn it and wait for it's termination. Is there any function that allows me to check if the application is still running using the HINSTANCE returned by ShellExecute? Or perhaps there is another, easy way to spawn an application in synchronous mode, that does not need any loops checking application's state? (that will eliminate senseless processor usage). Thanks in advance for any suggestions. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

        R Offline
        R Offline
        Ranjan Banerji
        wrote on last edited by
        #3

        On the same subject I have a question to ask. I have a parent application from which I would like to spawn other applications such that the other applications do not show up on the taskbar and that they can be terminated by the parent. I think the termination part maybe be easy but not sure about the taskbar part. The spawned applications are not mine, so how they work is not under my control.

        N D R 3 Replies Last reply
        0
        • C CoY0te

          Pretty simple - I use: ShellExecute() to spawn another application. I use this function because it allows me to specify the directory for spawned application. Now I need to wait for the application to terminate (In fact i would like to spawn it in synchronous mode because I just want to spawn it and wait for it's termination. Is there any function that allows me to check if the application is still running using the HINSTANCE returned by ShellExecute? Or perhaps there is another, easy way to spawn an application in synchronous mode, that does not need any loops checking application's state? (that will eliminate senseless processor usage). Thanks in advance for any suggestions. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

          J Offline
          J Offline
          Joshua Nussbaum
          wrote on last edited by
          #4

          for simple applications or commands I use C's system() function. You can also look into the _exec* functions. But the system() function is generally good enough. example: system("notepad.exe"); system("copy c:\myfile.txt c:\backup\myfile.txt");

          C 1 Reply Last reply
          0
          • T Tomasz Sowinski

            Use ShellExecuteEx. It gives you back the handle of spawned process, ready to use with WaitForSingleObject. Tomasz Sowinski -- http://www.shooltz.com

            What is "scratch" and why can everything be made from it?

            C Offline
            C Offline
            CoY0te
            wrote on last edited by
            #5

            Thank You. Easy as 1..2..3 :) [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

            1 Reply Last reply
            0
            • J Joshua Nussbaum

              for simple applications or commands I use C's system() function. You can also look into the _exec* functions. But the system() function is generally good enough. example: system("notepad.exe"); system("copy c:\myfile.txt c:\backup\myfile.txt");

              C Offline
              C Offline
              CoY0te
              wrote on last edited by
              #6

              I'll keep that in mind. These functions might be useful, allthough they do not allow You to specify the work directory for an application. Thank You. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

              J 1 Reply Last reply
              0
              • C CoY0te

                I'll keep that in mind. These functions might be useful, allthough they do not allow You to specify the work directory for an application. Thank You. [ CoY0te ] Railgun is like a Gilette Mach 3 - it does the job with one, easy stroke.

                J Offline
                J Offline
                Joshua Nussbaum
                wrote on last edited by
                #7

                That is correct, it defaults to the parent process's current directory. But I beleive u can do this: system("CD c:\my-start-up-dir"); system("notepad test.txt"); this would open the file c:\my-start-up-dir\test.txt

                1 Reply Last reply
                0
                • R Ranjan Banerji

                  On the same subject I have a question to ask. I have a parent application from which I would like to spawn other applications such that the other applications do not show up on the taskbar and that they can be terminated by the parent. I think the termination part maybe be easy but not sure about the taskbar part. The spawned applications are not mine, so how they work is not under my control.

                  N Offline
                  N Offline
                  Nick Parker
                  wrote on last edited by
                  #8

                  Not sure if this will help but here is a link to spawning processes[^]. Nick Parker


                  1 Reply Last reply
                  0
                  • R Ranjan Banerji

                    On the same subject I have a question to ask. I have a parent application from which I would like to spawn other applications such that the other applications do not show up on the taskbar and that they can be terminated by the parent. I think the termination part maybe be easy but not sure about the taskbar part. The spawned applications are not mine, so how they work is not under my control.

                    D Offline
                    D Offline
                    Daniel Lohmann
                    wrote on last edited by
                    #9

                    If the spawned apps do not need to be visible for the user and you are on NT, you could just run them on a different desktop. This is the way the system uses to ensure that service processes are not used interactive. I have never tested it on myself, but AFAIK all you have to do is to pass a new desktop and maybe also a new window station name in the lpDesktop param of STARTUPINFO. If the desktop does not exist yet, the system creates it for you. -- Daniel Lohmann http://www.losoft.de (Hey, this page is worth looking! You can find some free and handy NT tools there :-D )

                    1 Reply Last reply
                    0
                    • R Ranjan Banerji

                      On the same subject I have a question to ask. I have a parent application from which I would like to spawn other applications such that the other applications do not show up on the taskbar and that they can be terminated by the parent. I think the termination part maybe be easy but not sure about the taskbar part. The spawned applications are not mine, so how they work is not under my control.

                      R Offline
                      R Offline
                      Roman Fadeyev
                      wrote on last edited by
                      #10

                      May be, this example will help you. Sorry i have no time to explain what does it mean. I hope, you will get it ..... STARTUPINFO si={0}; si.cb = sizeof(si); si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; si.wShowWindow = SW_HIDE; <<-------- Here we hide window si.hStdOutput = hWrite; si.hStdError = hWrite; PROCESS_INFORMATION pi; CreateProcess (szCompilerName,szCommandLine, NULL,NULL,true,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi)

                      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