if (argc==2)
{
SC_HANDLE schSCManager = OpenSCManager(
NULL, // local machine
NULL, // ServicesActive database
SC_MANAGER_ALL_ACCESS); // full access rights
::strupr(argv[1]);
if (strcmp(argv[1],"-INSTALL")==0)
InstallService(schSCManager);
else if (strcmp(argv[1],"-UNINSTALL")==0)
UnInstallService(schSCManager);
CloseServiceHandle(schSCManager);
return 1;
}
else if (argc==3)
{
::strupr(argv[1]);
CString strServer=argv[2];
if (strcmp(argv[1],"-RINSTALL")==0)
RemoteInstall(strServer);
else if (strcmp(argv[1],"-RUNINSTALL")==0)
RemoteUnInstall(strServer);
return 1;
}
SC_HANDLE schService = CreateService(
hSCM, // SCManager database
lpszServiceName, // name of service
lpszDisplayName, // service name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_AUTO_START, // start type
SERVICE_ERROR_NORMAL, // error control type
szBinaryPathName, // service's binary
NULL, // no load ordering group
NULL, // no tag identifier
NULL, // no dependencies
NULL, // LocalSystem account
NULL); // no password
if (schService == NULL)
printf("InstallService ERROR.\n");
else
printf("InstallService SUCCESS.\n");