1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
int _tmain(int argc, _TCHAR* argv[])
{
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{ SERVICE_NAME, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
{ NULL, NULL }
};
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
hService = OpenService(hSCManager,SERVICE_NAME, SERVICE_ALL_ACCESS);
if(argc == 2) {
if(_tcscmp(argv[1], TEXT("-u")) == 0)
MyServiceDelete(SERVICE_NAME);
if(_tcscmp(argv[1], TEXT("-i")) == 0){
MyServiceInstall(SERVICE_NAME);
StartService(hService,0,0);
}
if(_tcscmp(argv[1], TEXT("-s")) == 0){
StartService(hService,0,0);
}
}else{
if(hService == NULL) {
MyServiceInstall(SERVICE_NAME);
//StartService(hService,0,0);
}
if (StartServiceCtrlDispatcher(DispatchTable) == 0)
{
SvcDebugOut(TEXT(" [MY_SERVICE] StartServiceCtrlDispatcher (%d)\n"),
GetLastError());
}
}
CloseServiceHandle(hService);
CloseServiceHandle(hSCManager);
return(0);
} |
Partager