Basically i'm using this shellexecuteex within servicestart(). my idea is
No, ShellExecuteEx returns a BOOL that is TRUE if successful or FALSE if
not.
If it is TRUE (1), then it started the process.
If it is FALSE (0), an error occurred and you have to call GetLastError() to
find out what the error code is.
The service knows when the application started with ShellExecuteEx closes
because you have the WaitForSingleObject(x,INFINITE) call. That call will
"block" (wait) forever until the process handle you passed to it has ended.
Then it returns. When a process ends, it's handle becomes "signaled" and
that trips WaitForSingleObject.
I'm not sure what you mean by preventing the service from stopping when the
application closes - as long as you stay in some sort of loop, it will not
end.
"ganesh" <ganesh@discussions.microsoft.com> wrote in message
news:7D124071-54E7-4C71-8FE8-D7B2803ED9D8@microsoft.com...
I believe it returns hProcess though i'm not able to capture it.
I removed the ResumeThread now.
One thing I couldn't figure out how does the service know the application
is
closed; and how do i prevent the service from stopping when the
application
is closed
"JJ" wrote:
ResumeThread won't work - that only resumes a thread that was previously
suspended with SuspendThread. A process that has ended is not
suspended -
it has ended.
Are you doing any error checking?
The second time through, what does ShellExecuteEx return?
"ganesh" <ganesh@discussions.microsoft.com> wrote in message
news:D4E809A2-C072-4BE0-B688-2AF8D5E00933@microsoft.com...
ResumeThread(ShExecInfo.hProcess); seems to work; however, the service
stops
once the app has been terminated
restart:
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = szPath;
ShExecInfo.lpParameters = ""; //"service";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
ResumeThread(ShExecInfo.hProcess);
//CloseHandle(ShExecInfo.hProcess);
goto restart;
"ganesh" wrote:
I created a service which uses shellexecuteex and WaitForSingleObject
to
open
an application. my requirement is to keep the app running until the
service
is stopped, even if the user terminates the app from task manager.
here
is my
code but it doesn't restart the app when it is closed. any help is
appreciated, thanks
restart:
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = szPath;
ShExecInfo.lpParameters = ""; //"service";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
CloseHandle(ShExecInfo.hProcess);
goto restart;