| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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, |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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);
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|