Installing a Service A service configuration program uses the CreateService function to install a service in a SCM database. The application-defined schSCManager handle must have SC_MANAGER_CREATE_SERVICE access to the SCManager object. The following example shows how to install a service. VOID CreateSampleService() { LPCTSTR lpszBinaryPathName = "%SystemRoot%\\system\\testserv.exe";
schService = CreateService( schSCManager, // SCManager database "Sample_Srv", // name of service lpszDisplayName, // service name to display SERVICE_ALL_ACCESS, // desired access SERVICE_WIN32_OWN_PROCESS, // service type SERVICE_DEMAND_START, // start type SERVICE_ERROR_NORMAL, // error control type lpszBinaryPathName, // service's binary NULL, // no load ordering group NULL, // no tag identifier NULL, // no dependencies NULL, // LocalSystem account NULL); // no password
if (schService == NULL) MyErrorExit("CreateService"); else printf("CreateService SUCCESS.\n");
CloseServiceHandle(schService); }
当然,这是注册一个应用成为NT/2000下的Service程序的方法。 Windows 9x下有另外的方法使一个应用注册成“后台”程序
A service configuration program uses the CreateService function to install a service in a SCM database. The application-defined schSCManager handle must have SC_MANAGER_CREATE_SERVICE access to the SCManager object. The following example shows how to install a service. VOID CreateSampleService()
{
LPCTSTR lpszBinaryPathName =
"%SystemRoot%\\system\\testserv.exe";
schService = CreateService(
schSCManager, // SCManager database
"Sample_Srv", // name of service
lpszDisplayName, // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type
lpszBinaryPathName, // service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
NULL, // LocalSystem account
NULL); // no password
if (schService == NULL)
MyErrorExit("CreateService");
else
printf("CreateService SUCCESS.\n");
CloseServiceHandle(schService);
}
Windows 9x下有另外的方法使一个应用注册成“后台”程序
在此表示多谢!非常感谢!