Trivial Win32 Service App not working

Roger Alcindor
Roger Alcindor used Ask the Experts™
on
I am writing a Win32 Service application using embarcadero XE 10.1 Berlin C++ builder on a 64 bit Windows 7 PC.

I am starting with a trivial project prior to putting "flesh on the bones", but can't get the simple example to work ?
when I run the application with /install as a command line parameter (which usually installs the service app), I get the following error instead.

    Exception EOSError in module KERNELBASE.dll at 0000C5AF.
    System Error. code 5
Access is denied.


I get this error regardless of whether or not the Beep function is called.
I have set the StartType to stDisabled so I would expect the service application to be installed but it isn't.
 The code is as follows, any help would be appreciated. I have written service applications before using Borland C++ builder but no Embarcadero XE C++ builder.


C++ file:
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TTestServiceName *TestServiceName;
//---------------------------------------------------------------------------
__fastcall TTestServiceName::TTestServiceName(TComponent* Owner)
	: TService(Owner)
{
}

void __stdcall ServiceController(unsigned CtrlCode)
{
	TestServiceName->Controller(CtrlCode);
}

TServiceController __fastcall TTestServiceName::GetServiceController(void)
{
	return (TServiceController) ServiceController;
}

//---------------------------------------------------------------------------
void __fastcall TTestServiceName::ServiceStart(TService *Sender, bool &Started)
{
    //Beep(1000,500);
}
//---------------------------------------------------------------------------

Open in new window


header file:
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <SvcMgr.hpp>
#include <vcl.h>
//---------------------------------------------------------------------------
class TTestServiceName : public TService
{
__published:    // IDE-managed Components
	void __fastcall ServiceStart(TService *Sender, bool &Started);
private:        // User declarations
public:         // User declarations
	__fastcall TTestServiceName(TComponent* Owner);
	TServiceController __fastcall GetServiceController(void);

	friend void __stdcall ServiceController(unsigned CtrlCode);
};
//---------------------------------------------------------------------------
extern PACKAGE TTestServiceName *TestServiceName;
//---------------------------------------------------------------------------
#endif

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
on a 64-bit windows you have both 32-bit and 64-bit services. i suppose your service is 32-bit.

the error code 5 means 'access denied'. most likely you should open a command window 'as administrator'. then navigate by cd commands to directory where the new service resides and try to install it there. if that doesn't work, you should use the sc scheduler to install the service. you can type

    sc /?

in the command window to see all options. you would use 'sc create' to install the service.

Sara

Author

Commented:
Thanks Sara,
I have got caught on that before (a couple of years ago) and had forgotten.
I installed the service app with elevated permissions and the error went away and installed the service.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial