Re: child process in windows services

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Anonuser (mycorolla02_at_yahoo.com)
Date: 03/17/04

  • Next message: Chandra: "System32 Folder pops up"
    Date: 16 Mar 2004 16:02:56 -0800
    
    

    Thanks John. Here are some more details/questions. Please see below.

    "John Phillips" <jjphillipsREMOVE@REMOVEhotmail.com> wrote in message news:<#Jn1j$1CEHA.2052@TK2MSFTNGP11.phx.gbl>...
    > Is A.exe a service by any chance? If not, just how will it report its
    > status back to the SCM? Or do you mean that the application is designed to
    > report its status to its parent or to whomever is interested in A's status?
    >

    A.exe is an executable which is launched via a Service. For eg. the
    Clib book service launches C:\WINNT\system32\clipsrv.exe.

    similary "serviceA" launches A.exe . So it is a service.

    > If A is a service, then the answer is simple: either make your service
    > dependant on A (so that A will start before your service and if it fails,
    > then your service will stop), or start A from your service using
    > StartService(). If you start a service via StartService(), then yes, the
    > newly started service will post its status to the SCM correctly. It's not
    > really a matter of who starts the service (your service vs. SCM vs. anybody
    > else), but if your service application -=behaves=- correctly, by calling the
    > requisite service registration function on startup, passing a handler
    > function. Also, the service must be registered via the appropriate registry
    > entries; statii reporting to the SCM for unregistered services will fall on
    > deaf ears.
    >

    This is a good way but well thats not what I intend to do. I will now
    make "SErviceA" to point to B.exe with some custom settings (like
    setting env. variables) and then within B.exe I want to call (launch)
    A.exe.

    Now when I started "ServiceA" from SCM b.exe gets launched followed by
    A.exe.

    ServiceA should show as failed even if b.exe or A.exe fails to run.
    If B.exe fails then ServiceA might show as failed even though A.exe is
    still running. So if B.exe fails A.exe should quit/fail and vice
    versa.

    I know this is complicated !!!
    Thanks

    > What to do to monitor A from B? Well, that depends on what you want to do.
    > If A is a service, then you can periodically check its status with
    > QueryServiceStatus(). Otherwise, you can use one of the WaitForxxxObjects()
    > functions to wait on A's process handle - when A terminates, the handle
    > becomes signalled, and WaitFor...() will succeed.
    >
    >

    "John Phillips" <jjphillipsREMOVE@REMOVEhotmail.com> wrote in message news:<#Jn1j$1CEHA.2052@TK2MSFTNGP11.phx.gbl>...
    > Is A.exe a service by any chance? If not, just how will it report its
    > status back to the SCM? Or do you mean that the application is designed to
    > report its status to its parent or to whomever is interested in A's status?
    >
    > If A is a service, then the answer is simple: either make your service
    > dependant on A (so that A will start before your service and if it fails,
    > then your service will stop), or start A from your service using
    > StartService(). If you start a service via StartService(), then yes, the
    > newly started service will post its status to the SCM correctly. It's not
    > really a matter of who starts the service (your service vs. SCM vs. anybody
    > else), but if your service application -=behaves=- correctly, by calling the
    > requisite service registration function on startup, passing a handler
    > function. Also, the service must be registered via the appropriate registry
    > entries; statii reporting to the SCM for unregistered services will fall on
    > deaf ears.
    >
    > What to do to monitor A from B? Well, that depends on what you want to do.
    > If A is a service, then you can periodically check its status with
    > QueryServiceStatus(). Otherwise, you can use one of the WaitForxxxObjects()
    > functions to wait on A's process handle - when A terminates, the handle
    > becomes signalled, and WaitFor...() will succeed.
    >
    >
    > --
    > John Phillips
    > MVP - Windows SDK
    >
    >
    >
    > "Anonuser" <mycorolla02@yahoo.com> wrote in message
    > news:32946381.0403151929.52fa2f97@posting.google.com...
    > > Hi John,
    > > Thanks for the reply. Here is a more detailed description.
    > >
    > > I have a service which launches process A.exe. A.exe is a third party
    > > process to which I dont have access. I want to create a wrapper around
    > > A or an intermediate process called B.exe.
    > >
    > > Not my service launches process B.exe which internally sets some
    > > environment variables and does a create process to launch A.exe.
    > >
    > > A.exe was initially built to report status back to the Service
    > > control manager.
    > > I have two choices.
    > > So from B.exe if I make a call to SErvice_Main (or equivalent) for
    > > A.exe then A.exe will think that is started by a service and then
    > > report status like STARTED, PENDING. Will these reach the Service
    > > Control Manager since A.exe is the child of process it(SCM) launched.
    > >
    > > OR
    > >
    > > if i directly do a createprocess in B.exe (to create A.exe) to launch
    > > it as an application. What all do I need to do in B.exe to correctly
    > > monitor A's status?
    > >
    > > What will happen if B fails but A is still hanging? What status will
    > > be reported back to SCM(Service control manager)?
    > >
    > > Thanks
    > >
    > >
    > >
    > > "John Phillips" <jjphillipsREMOVE@REMOVEhotmail.com> wrote in message
    > news:<#xQ8cdpCEHA.3344@tk2msftngp13.phx.gbl>...
    > > > Please see inline...
    > > >
    > > >
    > > > --
    > > > John Phillips
    > > > MVP - Windows SDK
    > > >
    > > >
    > > > "Anonuser" <mycorolla02@yahoo.com> wrote in message
    > > > news:32946381.0403131419.7c20251d@posting.google.com...
    > > > > I have a service which calls into an exec by the name A.exe. Can I
    > > >
    > > > I don't know what you mean by "calls into an exec". Do you mean
    > "launches a
    > > > process"?
    > > >
    > > >
    > > > > write a wrapper around A.exe called B.exe which basically does some
    > > > > custom settings( settng Env variables) and then call A.exe. So A.exe
    > > >
    > > > Certainly. The environment settings of the parent are passed to the
    > child
    > > > process when calling CreateProcess() and passing NULL for the
    > lpEnvironment
    > > > parameter.
    > > >
    > > >
    > > > > is the child of B.exe. Would service update messages sent by A.exe be
    > > > > passed to the Service control manager. What all functions do I need to
    > > >
    > > > I'm still foggy about which of these things are services (B I assume is
    > > > not). But assuming A is launched by a service, then the answer is no.
    > > > SetServiceStatus() requires a handle to the service which is sending its
    > > > status, and I'm pretty sure that these handles can't be duplicated with
    > > > DuplicateHandle(). One way you might accomplish this is for A to send
    > > > messages to the service (via some IPC method such as COM, Window
    > Messages,
    > > > Pipes, etc., etc., etc.), and the service would call SetServiceStatus()
    > > &g
    8
    t; based
    68f
     on the content of the message.
    > > >
    > > >
    > > > > write in the code for B.exe.
    > > >
    > > > You haven't mentioned what B is supposed to do, so this isn't really a
    > valid
    > > > question.
    > > >
    > > > >
    > > > > When A.exe dies will the service control manager report the service as
    > > > > stopped?
    > > >
    > > > No, unless the service tells the SCM that it is stopped. When A dies,
    > it
    > > > can instruct the service to stop, via some IPC mechanism (see above).
    > > >
    > > >
    > > > > Would I have to monitor A.exe's state in B? I cannot put these custom
    > > > > settings into A.exe.
    > > >
    > > > Really can't say, seeing as how you're a little short on details.
    > > >
    > > >
    > > > > Thanks


  • Next message: Chandra: "System32 Folder pops up"

    Relevant Pages

    • Re: child process in windows services
      ... example, if B.exe launches A.exe, then B.exe can pass it's process handle to ... Or do you mean that the application is designed to>> report its status to its parent or to whomever is interested in A's status? ... >> dependant on A, or start A from your service using ... If you start a service via StartService, then yes, the>> newly started service will post its status to the SCM correctly. ...
      (microsoft.public.win2000.developer)
    • Re: child process in windows services
      ... just how will it report its ... newly started service will post its status to the SCM correctly. ... > Not my service launches process B.exe which internally sets some> environment variables and does a create process to launch A.exe. ... Will these reach the Service> Control Manager since A.exe is the child of process itlaunched. ...
      (microsoft.public.win2000.developer)
    • Re: build a nt service that cannot be stopped and disabled
      ... Building a service that can't be stopped is relatively easy, you just report that it can't be stopped back to the SCM in the SERVICE_STATUS_PROCESS structure. ... Omar wrote: ...
      (microsoft.public.win32.programmer.kernel)
    • Re: build a nt service that cannot be stopped and disabled
      ... Building a service that can't be stopped is relatively easy, you just report that it can't be stopped back to the SCM in the SERVICE_STATUS_PROCESS structure. ... Omar wrote: ...
      (microsoft.public.win32.programmer.kernel)
    • US Military Academy at West Point Launches Center for Oral
      ... US Military Academy at West Point Launches 'Center for Oral ... U.S. and friendly nation laws prohibit fully ... with our laws this report cannot be provided in ...
      (soc.history.war.misc)