How to manipulate with processes from your app? Any help is appreciated
-
The problem: big bad legacy application with code written from 1996 onward. Application starts another process (utility app written on .Net), original idea was to start utility app in background during loading time and to close it when main application is closing. Now someone wants ability to close it whenever one wants. All that is rather simple to comprehend, but what worries me how to inform main application that utility app is closed? Main app has utility's process handle and it made me to believe everything will be easy... This is code for utility start:
void CFireAdder::StartService(void)
{
CString planBrowserPath;
#ifdef DEBUG
planBrowserPath = CUtils::AddPathToWorkingPath("Debug\\FireAdder");
#else
planBrowserPath = CUtils::AddPathToWorkingPath("FireAdder");
#endifplanBrowserPath = CUtils::AddFilenameToPath(planBrowserPath,"FireAdder.exe");
TRACE("starting planbrowser... "); \_process=(HANDLE)\_spawnl(\_P\_NOWAIT,planBrowserPath,"FireAdder",NULL); WaitForInputIdle(\_process,INFINITE); TRACE("... started\\n");
}
And this is little piece of code I've written for getting utility's window handle:
HWND CFireAdder::getWindowHandle()
{
if(_process == (HANDLE) -1) return NULL;//if(\_windowHandle != NULL) return \_windowHandle; DWORD procID = GetProcessId(\_process); if(procID > 0){ //:) I know it's ugly but I was in a hurry HWND hw = FindWindow("WindowsForms10.Window.8.app.0.378734a","FireAdder - pregled reklama"); //\_windowHandle = hw; return hw; } \_process = (HANDLE) -1; return NULL;
}
I though I could use same recipe for checking if utility app is closed, but above mentioned code does not return NULL, I thought GetProcessID will return 0! Can someone tell me how to check whether utility process is still active in more inteligent way? I am .Net brat with limited C++ Windows programming experience. Excuse me for bad grammar or spelling, I am in a hurry.
-
The problem: big bad legacy application with code written from 1996 onward. Application starts another process (utility app written on .Net), original idea was to start utility app in background during loading time and to close it when main application is closing. Now someone wants ability to close it whenever one wants. All that is rather simple to comprehend, but what worries me how to inform main application that utility app is closed? Main app has utility's process handle and it made me to believe everything will be easy... This is code for utility start:
void CFireAdder::StartService(void)
{
CString planBrowserPath;
#ifdef DEBUG
planBrowserPath = CUtils::AddPathToWorkingPath("Debug\\FireAdder");
#else
planBrowserPath = CUtils::AddPathToWorkingPath("FireAdder");
#endifplanBrowserPath = CUtils::AddFilenameToPath(planBrowserPath,"FireAdder.exe");
TRACE("starting planbrowser... "); \_process=(HANDLE)\_spawnl(\_P\_NOWAIT,planBrowserPath,"FireAdder",NULL); WaitForInputIdle(\_process,INFINITE); TRACE("... started\\n");
}
And this is little piece of code I've written for getting utility's window handle:
HWND CFireAdder::getWindowHandle()
{
if(_process == (HANDLE) -1) return NULL;//if(\_windowHandle != NULL) return \_windowHandle; DWORD procID = GetProcessId(\_process); if(procID > 0){ //:) I know it's ugly but I was in a hurry HWND hw = FindWindow("WindowsForms10.Window.8.app.0.378734a","FireAdder - pregled reklama"); //\_windowHandle = hw; return hw; } \_process = (HANDLE) -1; return NULL;
}
I though I could use same recipe for checking if utility app is closed, but above mentioned code does not return NULL, I thought GetProcessID will return 0! Can someone tell me how to check whether utility process is still active in more inteligent way? I am .Net brat with limited C++ Windows programming experience. Excuse me for bad grammar or spelling, I am in a hurry.
You've got a process handle - you can use GetExitCodeProcess[^] to see if the process has termnated or not - GetExitCodeProcess returns TRUE and the output status is STILL_ACTIVE if the process is still there.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
The problem: big bad legacy application with code written from 1996 onward. Application starts another process (utility app written on .Net), original idea was to start utility app in background during loading time and to close it when main application is closing. Now someone wants ability to close it whenever one wants. All that is rather simple to comprehend, but what worries me how to inform main application that utility app is closed? Main app has utility's process handle and it made me to believe everything will be easy... This is code for utility start:
void CFireAdder::StartService(void)
{
CString planBrowserPath;
#ifdef DEBUG
planBrowserPath = CUtils::AddPathToWorkingPath("Debug\\FireAdder");
#else
planBrowserPath = CUtils::AddPathToWorkingPath("FireAdder");
#endifplanBrowserPath = CUtils::AddFilenameToPath(planBrowserPath,"FireAdder.exe");
TRACE("starting planbrowser... "); \_process=(HANDLE)\_spawnl(\_P\_NOWAIT,planBrowserPath,"FireAdder",NULL); WaitForInputIdle(\_process,INFINITE); TRACE("... started\\n");
}
And this is little piece of code I've written for getting utility's window handle:
HWND CFireAdder::getWindowHandle()
{
if(_process == (HANDLE) -1) return NULL;//if(\_windowHandle != NULL) return \_windowHandle; DWORD procID = GetProcessId(\_process); if(procID > 0){ //:) I know it's ugly but I was in a hurry HWND hw = FindWindow("WindowsForms10.Window.8.app.0.378734a","FireAdder - pregled reklama"); //\_windowHandle = hw; return hw; } \_process = (HANDLE) -1; return NULL;
}
I though I could use same recipe for checking if utility app is closed, but above mentioned code does not return NULL, I thought GetProcessID will return 0! Can someone tell me how to check whether utility process is still active in more inteligent way? I am .Net brat with limited C++ Windows programming experience. Excuse me for bad grammar or spelling, I am in a hurry.
try using IsWindow api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
You've got a process handle - you can use GetExitCodeProcess[^] to see if the process has termnated or not - GetExitCodeProcess returns TRUE and the output status is STILL_ACTIVE if the process is still there.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Thank you! It works as expected.
-
try using IsWindow api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
I'll try it later, so far above mentioned solution satisfies me.