Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Handling Win XP services with MFC

13 views
Skip to first unread message
Message has been deleted

Uwe Kotyczka

unread,
Sep 7, 2010, 3:32:24 AM9/7/10
to
On 6 Sep., 18:40, dave <d...@127.0.0.1> wrote:
> I am well and truly out of the loop using mfc - last used it several
> years ago. I still have visual studio (VC++ 6.0) installed here though
> :-)
>
> I would just like to ask if mfc has any way to monitor (and/or
> control) the services running on a Windows XP PC?
>
> I can't seem to find a tool for doing that and thought maybe it would
> be possible to write such a thing.
>
> Any pointers (no pun intended) as to how to go about the above,
> appreciated.

Unfortunately this group has almost no traffic any more.
(F'up2 microsoft.public.vc.mfc)

Daniel Weber

unread,
Sep 8, 2010, 3:20:33 PM9/8/10
to Uwe Kotyczka
Am 07.09.2010 09:32, schrieb Uwe Kotyczka:
> Unfortunately this group has almost no traffic any more.
> (F'up2 microsoft.public.vc.mfc)

microsoft.public.vc.mfc will be finally removed this autumn (maybe it
has already been removed on Microsofts servers), so I would recommend
staying here.

Regarding the original question, MFC does AFAIK not provide any service
specific classes, but it is not so complicated to control services via
the Windows API:

OpenSCManager
OpenService
StartService
ControlService
QueryServiceStatus
CloseServiceHandle

Bye,
Daniel

Joseph M. Newcomer

unread,
Sep 8, 2010, 4:52:58 PM9/8/10
to
I missed the original question.

Bottom line: MFC isn't very useful for system services. You shouldn't use it in the
services, and the APIs, as pointed out below, are sufficiently trivial that you could
build your own class(es) around them.

class Service {
public:
Service(const CString & svcname) { name = svcname; svc = NULL; }
BOOL Open()
{
HANDLE scm = ::OpenSCManager();
if(scm == NULL)
return FALSE;
svc = OpenService(scm, name);
if(svc == NULL)
{
::CloseHandle(scm);
return FALSE;
}
::CloseHandle(scm);
return TRUE;
}
BOOL StartService() {
{
ASSERT(svc != NULL);
if(svc == NULL)
return FALSE;
if(!::StartService(svc))
return FALSE;
return TRUE;
}
protected:
HANDLE svc;
CString name;
};

I did this off the top of my head, without even referring to the documentation, but I
believe it is close enough to the truth to show what you might consider doing. You can
write the other methods As An Exercise For The Reader.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages