|
-
November 3rd, 2009, 06:23 PM
#1
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,
-
November 4th, 2009, 11:01 AM
#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.
-
November 4th, 2009, 11:24 AM
#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);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|