Regarding Windows services
well am suppose to create a software in which a adminstrator can set a pattern of file name in a conf file.This Software will have a service running in the background that will remove files from the system. The service will read names from a configuration file and remove those files which will have any of these names in the filename.
Can anybody give me an guideline of how to go about it?.....i heard that ATL com wizard can be used for creating windows services....if yes then can you please tell me how to go about it??.......thanks in advance!!
please help urgently......
Re: Regarding Windows services
You need a simple Windows service for this.
You don't really need a COM service here.
Re: Regarding Windows services
ATL makes a great service platform. Sure the wizard adds COM when it generates the classes, but it's easy enough to remove the COM code.
@OP What version of Visual C++ are you running?
Re: Regarding Windows services
can you please tell some steps to create such service....
Re: Regarding Windows services
Re: Regarding Windows services
Pretty much all you need to do is create a new project. Walk through the New project wizard and choose the ATL project template. When the new project wizard opens, choose Service (EXE) server type. After the code gets generated, remove the COM related registration code.
Sorry, I don't have VC6 installed (it's 11 years old btw) so I can't give you more detailed instructions.
Re: Regarding Windows services
ok fine but after the code is generated can you please tell where shall i place my code that is to be executed in background that is deletion of files for the service.....am totally new to this type of programs so kindly avoid my mistakes.......
Re: Regarding Windows services
Quote:
Originally Posted by
pinnachio
ok fine but after the code is generated can you please tell where shall i place my code that is to be executed in background that is deletion of files for the service.....am totally new to this type of programs so kindly avoid my mistakes.......
I really can't because VC6 is so old and the newer versions have changed the code generation slightly.
However, if you generate a new ATL service project, then remove the .ncb, debug and release folders, you can zip the project up and post it here. Then I can look at it.
1 Attachment(s)
Re: Regarding Windows services
i have attached my set of codes here by........
Re: Regarding Windows services
Comment out the following
Code:
// Add object entries
hr = CComModule::RegisterServer(bRegTypeLib);
// Remove object entries
CComModule::UnregisterServer(TRUE);
hr = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, REGCLS_MULTIPLEUSE);
_ASSERTE(SUCCEEDED(hr));
_Module.RevokeClassObjects();
I would abstract the implementation from the boiler plate code and create a class called CAbcService (or whatever is appropriate). I would put all my functional code inside that and create a class member inside the CServiceModule class.
Then just call the appropriate methods.
Code:
inlinevoid CServiceModule::Handler(DWORD dwOpcode)
{
switch (dwOpcode)
{
case SERVICE_CONTROL_STOP:
SetServiceStatus(SERVICE_STOP_PENDING);
PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
m_AbcService.Stop( );
break;
case SERVICE_CONTROL_PAUSE:
m_AbcService.Pause( );
break;
case SERVICE_CONTROL_CONTINUE:
m_AbcService.Continue( );
break;
case SERVICE_CONTROL_INTERROGATE:
break;
case SERVICE_CONTROL_SHUTDOWN:
m_AbcService.Shutdown( );
break;
default:
LogEvent(_T("Bad service request"));
}
}
In the CServiceModule::Run(), add m_AbcService.Start( ); before the LogEvent( _T("Service Started") ) call.
Re: Regarding Windows services
well i also wish to know that where i shall place my code of the service( i.e. as per my problem deleting all files of the given names in config file) after commenting the above code.........
Re: Regarding Windows services
Quote:
Originally Posted by
pinnachio
well i also wish to know that where i shall place my code of the service( i.e. as per my problem deleting all files of the given names in config file) after commenting the above code.........
I was referring to where to put your code when I talked about....
Code:
I would abstract the implementation from the boiler plate code and create a class
To expand a bit. Create a class that contains the functionality you desire and exposes a couple of public methods (such as Start, Stop, Pause, etc). Then just create a member variable of this class inside the CServiceModule class. Then wire up the appropriate public methods in the Run() method and Handler method (as shown above).
Re: Regarding Windows services
can you tell some link so that I could get more information about the topic??any ways thanks for the above help it really helped me....
Re: Regarding Windows services
Quote:
Originally Posted by
pinnachio
can you tell some link so that I could get more information about the topic??any ways thanks for the above help it really helped me....
What I am suggesting is to build a class with public methods and can't really suggest a link other than advice to put up a C++ book if you don't know how to create a class.
Re: Regarding Windows services
ATL Wizard gives more of a point-and-click approach. If you want to see what's happening "under-the-hood", or make a service without the use of ATL check this, or this link from Microsoft.
Re: Regarding Windows services
Well i dont have any problems regarding classes and functions you told me to add, i only wished to know about this services in detail...
Re: Regarding Windows services
When you asked for a link 'about the topic', it's not very specific. So what documentation are you looking for? Windows Service documentation? ATL Service documentation?
Here's an article using ATL.
http://www.codeguru.com/cpp/com-tech...icle.php/c3553