CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 3rd, 2009, 06:23 PM
    Shaitan00 Shaitan00 is offline
    Member
     
    Join Date: Oct 2004
    Posts: 419
    Shaitan00 is on a distinguished road (10+)
    Question Proper way to delay an application while a service is starting?

    My system has a service (Serv.exe) which starts as LocalSystem and should be running at all time, additionally on startup of the PC (auto logon) the user has a STARTUP application (App.exe) which runs.

    Sadly I've found that sometimes App.exe starts to run before Serv.exe has finished starting, and one of the first thing App.exe does is communicate with Serv.exe (which obviously fails).

    So, I am looking for the proper way to handle this situation (I assume it isn't that rare)...
    I know I can query the service from App.exe for a specific amount of time but that doesn't seem like a clean solution.

    One thought I had ... just not sure if it is possible ... can you delay windows from allowing the user to login (or autologin) until the LocalSystem Services are running?

    Any help/hints would be greatly appreciated.
    Thanks,
    Reply With Quote
      #2    
    Old November 4th, 2009, 11:01 AM
    OReubens OReubens is offline
    Senior Member
     
    Join Date: Apr 2000
    Location: Belgium (Europe)
    Posts: 2,038
    OReubens  is a jewel in the rough (300+)OReubens  is a jewel in the rough (300+)OReubens  is a jewel in the rough (300+)OReubens  is a jewel in the rough (300+)
    Re: Proper way to delay an application while a service is starting?

    You can force this, but you don't really want to... as it's a "nasty" solution. Doing so would involve making the Desktop service dependant on your service.
    A result of that however is that you can't stop and restart your service anymore.

    The clean solution is to wait for the service to come up (ideally with a timeout and a means for the user to abort). A simpler solution is to give an error message if the service isn't running and abort, expecting the user to manually retry later.
    Reply With Quote
      #3    
    Old November 4th, 2009, 11:24 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,189
    hoxsiew  is a jewel in the rough (300+)hoxsiew  is a jewel in the rough (300+)hoxsiew  is a jewel in the rough (300+)hoxsiew  is a jewel in the rough (300+)
    Re: Proper way to delay an application while a service is starting?

    Use the service API:

    Code:
    #include <Winsvc.h>
    
    //...
      SC_HANDLE hsv,hmc;
      SERVICE_STATUS sst;
      hsv=OpenSCManager(NULL,0,SC_MANAGER_CONNECT);
      hmc=OpenService(hsv,L"MyService",GENERIC_READ);
      if(hmc==NULL){
        //service not installed; handle error
      }
      QueryServiceStatus(hmc,&sst);
      if(SERVICE_RUNNING!=sst.dwCurrentState){
        //wait or do whatever until it starts
      }
      CloseServiceHandle(hmc);
      CloseServiceHandle(hsv);
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 12:54 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009