srk_karthik
asked on
My Service crashes in XP machine and not in other OS
Requirement : I need to run a service in a XP machine from a remote windows (NT/2K/XP) machine using C program.
The service exe in the XP machine crashes after execution.
Description : I have "test.exe" ,a service exe , that calls "StartServiceCtrlDispatche r()" method. This exe is put in a specific location in
a XP Machine. I have another C program that will install (a service named 'Test') and run the service ('Test'), This C program will reside in a remote machine (NT/XP/2K). On running the service (using the C Program) test.exe will be exectuted.
The service in XP Machine is created using the 'local account' (by passing username and password as NULL for CreateService() method).
When i run the service using StartService() method, the test.exe runs in the remote machine and crashes at the end.
What may be the reason that it crashes.???!!!
Hint 1 : This (crash) happens only when the test.exe is run in the XP machine. It works fine when run in any other Windows OS.
Hint 2 : after debugging the C program (that installs/ runs the service), and putting some logs in the test.exe, i came to know that
the crash happenned only after the COMPLETE execution of test.exe in the remote (XP machine). i.e, i was able to print a log at the
last line of test.exe.
Does any one have an idea of where the problem could be??
-SRK
The service exe in the XP machine crashes after execution.
Description : I have "test.exe" ,a service exe , that calls "StartServiceCtrlDispatche
a XP Machine. I have another C program that will install (a service named 'Test') and run the service ('Test'), This C program will reside in a remote machine (NT/XP/2K). On running the service (using the C Program) test.exe will be exectuted.
The service in XP Machine is created using the 'local account' (by passing username and password as NULL for CreateService() method).
When i run the service using StartService() method, the test.exe runs in the remote machine and crashes at the end.
What may be the reason that it crashes.???!!!
Hint 1 : This (crash) happens only when the test.exe is run in the XP machine. It works fine when run in any other Windows OS.
Hint 2 : after debugging the C program (that installs/ runs the service), and putting some logs in the test.exe, i came to know that
the crash happenned only after the COMPLETE execution of test.exe in the remote (XP machine). i.e, i was able to print a log at the
last line of test.exe.
Does any one have an idea of where the problem could be??
-SRK
ASKER
Yes, the following code in test.exe does that :
-------------------------- ---------- ---------- ---------- ----
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
void
ControlHandler(DWORD request) {
switch(request)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
ServiceStatus.dwWin32ExitC ode = 0;
ServiceStatus.dwCurrentSta te = SERVICE_STOPPED;
SetServiceStatus (hStatus, &ServiceStatus);
return;
default:
break;
}
SetServiceStatus (hStatus, &ServiceStatus);
return;
}
-------------------------- ---------- ---------- ---------- ----
The above ControlHandler(DWORD) method
is registered using RegisterServiceCtrlHandler ()
-SRK
--------------------------
SERVICE_STATUS ServiceStatus;
SERVICE_STATUS_HANDLE hStatus;
void
ControlHandler(DWORD request) {
switch(request)
{
case SERVICE_CONTROL_STOP:
case SERVICE_CONTROL_SHUTDOWN:
ServiceStatus.dwWin32ExitC
ServiceStatus.dwCurrentSta
SetServiceStatus (hStatus, &ServiceStatus);
return;
default:
break;
}
SetServiceStatus (hStatus, &ServiceStatus);
return;
}
--------------------------
The above ControlHandler(DWORD) method
is registered using RegisterServiceCtrlHandler
-SRK
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Services typically run "forever" or until specifically stopped by another process (such as "Manage Services").
Does Test.exe tell the host O/S that it is terminating and will no longer be a running service?
Kent