🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7891

Re: Controlling Windows service

#7891
From: Remy Lebeau (TeamB)
Date: Mon, 13 Dec 2004 12:15
52 lines
3205 bytes
"Deepak Mishra" <deepak.dmishra@gmail.com> wrote in message
news:41bd5410$1@newsgroups.borland.com...

> Now the requirement is such that this process should be triggered
> whenever the first user logs in to the system and should stop when
> the last user logs out of the system.

Your service will need to register itself with the OS to receive user login
events.  The problem is, if you use Borland's TService framework, you will
not be able to do that.  You will have to write the service code completely
from scratch so that you can call the additional API functions that are
required which TService does not natively call - specially
RegisterServiceCtrlHandlerEx(), having the callback function look for
SERVICE_CONTROL_SESSIONCHANGE notifications.

I should mention, however, that this only works for WinXP and newer OSes.
For versions prior to XP, the only way to detect user logins/logouts are to
either:

1) write your own GINA.DLL to replace the native one.  GINA.DLL is the file
that receives CTRL-ALT-DEL requests and controls the WinLogon screen.

2) have the service continously poll for the current logged in user.
Enumerate the active processes looking for Explorer.exe, and then query the
user creditials from it via OpenProcessToken(), GetTokenInformation(), and
LookupAccountSid().

> Also, there should be some mechanism by which the end-user can
> control this process. That is, the client application should also have
> a button for initiating and terminating the process

Just start and stop the service like any other service.  Look at the
StartService() and ControlService() functions.

> Now my concern is when the process is triggered automatically,
> then the client application will neither have the "PID" nor the
> "Process Handle".

It does not need that information in the first place.

> In such a scenario, can that process be terminated by its process name?

Just stop the service.  Look at the ControlService() function.

> Also, can we check the status of a process by its name so that we can
> restrict the user from running multiple instances of the same process?

Services do not allow multiple instances to begin with.


Gambit
Technical Details
Message-ID: <41bd87dc$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!prodigy.com!newsswing.news.prodigy.com!prodigy.net!newsfeed.cwix.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <41bd5410$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2580bf3649196f02
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41bd5410$1@newsgroups.borland.com>
Subject: Re: Controlling Windows service
Date: Mon, 13 Dec 2004 04:15:53 -0800
Lines: 54
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <41bd87dc$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1102940124 68.69.17.41 (13 Dec 2004 04:15:24 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!prodigy.com!newsswing.news.prodigy.com!prodigy.net!newsfeed.cwix.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail