Spawning another application
-
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 theHINSTANCE
returned byShellExecute
? 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. -
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 theHINSTANCE
returned byShellExecute
? 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.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?
-
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 theHINSTANCE
returned byShellExecute
? 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.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.
-
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 theHINSTANCE
returned byShellExecute
? 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.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");
-
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?
-
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");
-
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.
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
-
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.
Not sure if this will help but here is a link to spawning processes[^]. Nick Parker
-
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.
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 )
-
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.
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)