CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    May 2009
    Posts
    88

    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......

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: Regarding Windows services

    You need a simple Windows service for this.
    You don't really need a COM service here.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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?

  4. #4
    Join Date
    May 2009
    Posts
    88

    Re: Regarding Windows services

    can you please tell some steps to create such service....

  5. #5
    Join Date
    May 2009
    Posts
    88

    Re: Regarding Windows services

    am using vc++ 6.0

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  7. #7
    Join Date
    May 2009
    Posts
    88

    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.......

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Regarding Windows services

    Quote Originally Posted by pinnachio View Post
    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.

  9. #9
    Join Date
    May 2009
    Posts
    88

    Re: Regarding Windows services

    i have attached my set of codes here by........
    Attached Files Attached Files

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.


  11. #11
    Join Date
    May 2009
    Posts
    88

    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.........

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Regarding Windows services

    Quote Originally Posted by pinnachio View Post
    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).

  13. #13
    Join Date
    May 2009
    Posts
    88

    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....

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Regarding Windows services

    Quote Originally Posted by pinnachio View Post
    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.

  15. #15
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured