Пример #1
0
void vStartService(void)
{
	SERVICE_STATUS ss;

	SC_HANDLE scmHandle = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if (scmHandle == NULL) // Perform error handling.
	{
		WriteLog(sLogFile, "(%d)서비스 매니저와 연결하는데, 오류가 발생하였습니다.\n", GetLastError() );
		return;
	}

	SC_HANDLE scHandle = OpenServiceA( scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS );

	StartService(scHandle,0,NULL);

	Sleep(2000);

	do
	{
		ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
		Sleep (100);
	} while (ss.dwCurrentState == SERVICE_START_PENDING);

	CloseServiceHandle(scHandle);

	return;
}
Пример #2
0
BOOL StartStopService(LPCSTR lpServiceName, BOOL bStop) {
	HANDLE hSCManager;
	HANDLE hService;
	SERVICE_STATUS ssStatus;
	BOOL ret = FALSE;
	hSCManager = OpenSCManagerA (NULL, NULL, SC_MANAGER_CREATE_SERVICE);
	if (hSCManager)	{
		hService = OpenServiceA (hSCManager, lpServiceName, SERVICE_START | DELETE | SERVICE_STOP);
		if (hService) {
			if (!bStop) {
				if (StartServiceA (hService, 0, NULL)) {
					eprintf ("Service started [OK]\n");
					ret = TRUE;
				} else {
					eprintf ("Service started [FAIL]\n");
				}
			} else {
				if (ControlService (hService, SERVICE_CONTROL_STOP, &ssStatus)) {
					eprintf ("Service Stopped [OK]\n");
					ret = TRUE;
				} else {
					eprintf ("Service Stopped [FAIL]\n");
				}
			}
			CloseServiceHandle (hService);
			DeleteService (hService);
		}
		CloseServiceHandle (hSCManager);
	}
	return ret;
}
Пример #3
0
void
vStartService (void)
{
  SERVICE_STATUS ss;
  SC_HANDLE scmHandle, scHandle;

  scmHandle = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

  if (scmHandle == NULL)
    {
      return;
    }

  scHandle = OpenServiceA (scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS);

  StartService (scHandle, 0, NULL);
  Sleep (2000);

  do
    {
      ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
      Sleep (100);
    }
  while (ss.dwCurrentState == SERVICE_START_PENDING);

  CloseServiceHandle (scHandle);
  CloseServiceHandle (scmHandle);

  return;
}
Пример #4
0
bool _stdcall StartWinIoDriver()
{
  SC_HANDLE hSCManager;
  SC_HANDLE hService;
  BOOL bResult;

  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
  if (hSCManager)
  {
    hService = OpenServiceA(hSCManager, "WinRing0_1_2_0", SERVICE_ALL_ACCESS);
    CloseServiceHandle(hSCManager); //liudonghua

    if (hService)
    {
      bResult = StartService(hService, 0, NULL); 

	 if(GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
	 {
		  bResult =true;
	  }
	 
      CloseServiceHandle(hService);
    }
    else{
      return false;
	}
  }
  else{	
    return false;
  }

  return bResult;
}
Пример #5
0
bool _stdcall StopWinIoDriver()
{
  SC_HANDLE hSCManager;
  SC_HANDLE hService;
  SERVICE_STATUS ServiceStatus;
  BOOL bResult;

  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

  if (hSCManager)
  {
    hService = OpenServiceA(hSCManager, "WinRing0_1_2_0", SERVICE_ALL_ACCESS);

    CloseServiceHandle(hSCManager);

    if (hService)
    {
      bResult = ControlService(hService, SERVICE_CONTROL_STOP, &ServiceStatus);
      CloseServiceHandle(hService);
    }
    else
      return false;
  }
  else
    return false;

  return bResult;
}
Пример #6
0
void
vPrintServiceStatus ()
{
  SERVICE_STATUS ss;
  SC_HANDLE scmHandle, scHandle;

  scmHandle = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

  if (scmHandle == NULL)
    {
      return;
    }

  scHandle = OpenServiceA (scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS);

  ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);

  if (ss.dwCurrentState == SERVICE_STOPPED)
    {
      fprintf (stdout, "SERVICE_STOPPED\n");
    }
  else
    {
      fprintf (stdout, "SERVICE_RUNNING\n");
    }

  CloseServiceHandle (scHandle);
  CloseServiceHandle (scmHandle);

  return;
}
Пример #7
0
// http://msdn.microsoft.com/en-gb/library/windows/desktop/ms686335.aspx
static void
restartService(const char *lpServiceName)
{
    SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    assert(hSCManager);
    if (!hSCManager) {
        return;
    }

    SC_HANDLE hService = OpenServiceA(hSCManager, lpServiceName, SC_MANAGER_ALL_ACCESS);
    assert(hService);
    if (!hService) {
        return;
    }

    SERVICE_STATUS_PROCESS ssp;
    DWORD cbBytesNeeded;
    QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE) &ssp, sizeof ssp, &cbBytesNeeded);

    BOOL bRet;
    if (ssp.dwCurrentState == SERVICE_RUNNING) {
        bRet = ControlService(hService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS) &ssp);
        assert(bRet);
        while (ssp.dwCurrentState != SERVICE_STOPPED) {
            Sleep(ssp.dwWaitHint);
            QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE) &ssp, sizeof ssp, &cbBytesNeeded);
        }
        bRet = StartService(hService, 0, NULL);
        assert(bRet);
    }

    CloseServiceHandle(hService);
    CloseServiceHandle(hSCManager);
}
Пример #8
0
void
vDelService (void)
{
  SC_HANDLE scmHandle = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

  if (scmHandle == NULL)	// Perform error handling.
    {
      WriteLog (sLogFile,
		"(%d)Cannot connect to the Windows Service Control Manager.\n",
		GetLastError ());
      return;
    }

  SC_HANDLE scHandle =
    OpenServiceA (scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS);

  SERVICE_STATUS ss;

  ss.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
  ss.dwCurrentState = SERVICE_STOP_PENDING;
  ss.dwControlsAccepted = 0;
  ss.dwWin32ExitCode = 0;
  ss.dwServiceSpecificExitCode = 0;
  ss.dwCheckPoint = 0;
  ss.dwWaitHint = 0;


  ControlService (scHandle, SERVICE_CONTROL_STOP, &ss);
  DeleteService (scHandle);

  return;
}
Пример #9
0
bool _stdcall RemoveWinIoDriver()
{
  SC_HANDLE hSCManager;
  SC_HANDLE hService;
  bool bResult;

  StopWinIoDriver();

  hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

  if (hSCManager)
  {
    hService = OpenServiceA(hSCManager, "WinRing0_1_2_0", SERVICE_ALL_ACCESS);

    CloseServiceHandle(hSCManager);

    if (hService)
    {
      bResult = DeleteService(hService);
      
      CloseServiceHandle(hService);
    }
    else
      return false;
  }
  else
    return false;

  return bResult;
}
Пример #10
0
DWORD MyDriver::LoadDriver(BOOL start)
{
	
	if(loaded)
		return DRV_SUCCESS;

	if(!initialized)
		return DRV_ERROR_NO_INITIALIZED;

	
	SC_HANDLE SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	DWORD retCode = DRV_SUCCESS;
	
	if (SCManager == NULL) 
		return DRV_ERROR_SCM;

    


    SC_HANDLE  SCService = CreateServiceA(SCManager,			  // SCManager database
									     driverName,            // nombre del servicio
							    		 driverName,            // nombre a mostrar
										 SERVICE_ALL_ACCESS,    // acceso total
										 SERVICE_KERNEL_DRIVER, // driver del kernel
										 SERVICE_DEMAND_START,  // comienzo bajo demanda
										 SERVICE_ERROR_NORMAL,  // control de errores normal
										 driverPath,	          // path del driver
										 NULL,                  // no pertenece a un grupo
										 NULL,                  // sin tag
										 NULL,                  // sin dependencias
										 NULL,                  // cuenta local del sistema
										 NULL                   // sin password
										 );
    
	if (SCService == NULL) 
	{
		SCService = OpenServiceA(SCManager, driverName, SERVICE_ALL_ACCESS);
		
		if (SCService == NULL) 
			retCode = DRV_ERROR_SERVICE;
	}

    CloseServiceHandle(SCService);
	SCService=NULL;

	CloseServiceHandle(SCManager);
	SCManager = NULL;

	
	if(retCode == DRV_SUCCESS)
	{
		loaded = TRUE;

		if(start)
			retCode = StarMyDriver();
	}

	return retCode;
}
Пример #11
0
DWORD MyDriver::StarMyDriver(void)
{

	if(started)
		return DRV_SUCCESS;


	SC_HANDLE SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	DWORD retCode;
	
	if (SCManager == NULL) 
		return DRV_ERROR_SCM;

    SC_HANDLE SCService = OpenServiceA(SCManager,
		                              (LPCSTR)driverName,
				                      SERVICE_ALL_ACCESS);
    
	if (SCService == NULL) 
        return DRV_ERROR_SERVICE;

    
    if (!StartService( SCService, 0, NULL)) 
	{
		
	
        if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING) 
		{
			removable = FALSE;

			retCode = DRV_SUCCESS;
		}

		else
			retCode = DRV_ERROR_STARTING;
    }

	else
		retCode = DRV_SUCCESS;

  
    CloseServiceHandle(SCService);
	SCService = NULL;

	CloseServiceHandle(SCManager);
	SCManager = NULL;

	
	if(retCode == DRV_SUCCESS)
	{
		started = TRUE;

		retCode = OpenDevice();
	}

    return retCode;
}
Пример #12
0
static int manage_service(int action) {
  static const char *service_name = "Mongoose";
  SC_HANDLE hSCM = NULL, hService = NULL;
  SERVICE_DESCRIPTIONA descr = {server_name};
  char path[PATH_MAX + 20];  // Path to executable plus magic argument
  int success = 1;

  if ((hSCM = OpenSCManager(NULL, NULL, action == ID_INSTALL_SERVICE ?
                            GENERIC_WRITE : GENERIC_READ)) == NULL) {
    success = 0;
    show_error();
  } else if (action == ID_INSTALL_SERVICE) {
    GetModuleFileNameA(NULL, path, sizeof(path));
    strncat(path, " ", sizeof(path));
    strncat(path, service_magic_argument, sizeof(path));
    hService = CreateServiceA(hSCM, service_name, service_name,
                             SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
                             SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
                             path, NULL, NULL, NULL, NULL, NULL);
    if (hService) {
      ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &descr);
    } else {
      show_error();
    }
  } else if (action == ID_REMOVE_SERVICE) {
    if ((hService = OpenServiceA(hSCM, service_name, DELETE)) == NULL ||
        !DeleteService(hService)) {
      show_error();
    }
  } else if ((hService = OpenServiceA(hSCM, service_name,
                                     SERVICE_QUERY_STATUS)) == NULL) {
    success = 0;
  }

  CloseServiceHandle(hService);
  CloseServiceHandle(hSCM);

  return success;
}
bool WinService::tryOpen() const
{
    if (!_svcHandle)
    {
#if defined(POCO_WIN32_UTF8)
        std::wstring uname;
        Poco::UnicodeConverter::toUTF16(_name, uname);
        _svcHandle = OpenServiceW(_scmHandle, uname.c_str(), SERVICE_ALL_ACCESS);
#else
        _svcHandle = OpenServiceA(_scmHandle, _name.c_str(), SERVICE_ALL_ACCESS);
#endif
    }
    return _svcHandle != 0;
}
Пример #14
0
//
//  FUNCTION: CmdStartService()
//
//  PURPOSE: Starts the service
//
//  PARAMETERS:
//
//  lpszServerName - Target server name. NULL for local machine
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
bool CNTService::Start(void) {
    SC_HANDLE   ServiceHandle;
    SC_HANDLE   ServiceManager;

    cout << "Attempting to start " << m_ServiceName << " ..." << endl;

    ServiceManager = OpenSCManagerA(
        NULL,                   // machine (NULL == local)
        NULL,                   // database (NULL == default)
        SC_MANAGER_ALL_ACCESS   // access required
        );

    if ( !ServiceManager ) {
        cout << "OpenSCManager failed." << endl;
        CObject::ShowLastError();
        return false;
    }


    ServiceHandle = OpenServiceA(ServiceManager, m_ServiceName.GetBuffer(), SERVICE_ALL_ACCESS);

    if (!ServiceHandle) {
        cout << "OpenService failed." << endl;
        CObject::ShowLastError();
        CloseServiceHandle (ServiceManager);
        return false;
    }
    

    if ( StartService( ServiceHandle, 0, NULL )) {
        cout << "Starting " << m_ServiceDisplayName << endl;
        base_sleep(1);
        while( QueryServiceStatus( ServiceHandle, &m_ServiceStatus) ) {
            if ( m_ServiceStatus.dwCurrentState == SERVICE_START_PENDING ) {
                cout << '.';
                cout.flush();
                base_sleep(1);
            } else break;
        }

        if ( m_ServiceStatus.dwCurrentState == SERVICE_RUNNING )
            cout << m_ServiceDisplayName << " started." << endl;
        else
            cout << m_ServiceDisplayName << " could not be started." << endl;
    }
    
    CloseServiceHandle (ServiceManager);
    CloseServiceHandle (ServiceHandle);
    return true;
}
Пример #15
0
BOOL CServiceModule::RemoveService(void)
{
	SC_HANDLE schMgr;
	SC_HANDLE schSvc;
	SERVICE_STATUS ss;

	schMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if (!schMgr)
	{
		printf("Unable to open SCManager.  Service not removed.\n");
		return FALSE;
	}

	schSvc = OpenServiceA(schMgr, c_szSvcName, SERVICE_ALL_ACCESS);

	if (!schSvc)
	{
		printf("Unable to open %s service.  Service not removed.\n", c_szSvcName);
		CloseServiceHandle(schMgr);
		return FALSE;
	}

	QueryServiceStatus(schSvc, &ss);

	if (ss.dwCurrentState != SERVICE_STOPPED)
	{
		printf("Unable to remove %s service while it is running.\n", c_szSvcName);
		CloseServiceHandle(schSvc);
		CloseServiceHandle(schMgr);
		return FALSE;
	}

	if (DeleteService(schSvc))
		printf("%s removed (as an NT Service).\n", c_szSvcName);
	else
	{
		char szBuf[MAX_PATH];
		sprintf(szBuf, "Unable to delete %s service.\n", c_szSvcName);

		DWORD dwErrorCode(GetLastError());
		PrintSystemErrorMessage(szBuf, dwErrorCode);
	}

	CloseServiceHandle(schSvc);
	CloseServiceHandle(schMgr);

	return TRUE;
}
Пример #16
0
static BOOL RemoveService(LPCSTR lpServiceName) {
	HANDLE hService;
	BOOL ret = FALSE;
	HANDLE hSCManager = OpenSCManagerA (NULL, NULL, SC_MANAGER_CREATE_SERVICE);
	if (hSCManager) {
		hService = OpenServiceA (hSCManager, lpServiceName, SERVICE_START | DELETE | SERVICE_STOP);
		if (hService) {
			DeleteService (hService);
			CloseServiceHandle (hService);
			ret = TRUE;
		}
		CloseServiceHandle (hSCManager);
	}
	return ret;
}
Пример #17
0
DWORD MyDriver::StopDriver(void)
{
	
	if(!started)
		return DRV_SUCCESS;


	SC_HANDLE SCManager = OpenSCManagerA(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	DWORD retCode;
	
	if (SCManager == NULL) 
		return DRV_ERROR_SCM;

   
    SERVICE_STATUS  status;

    SC_HANDLE SCService = OpenServiceA(SCManager, driverName, SERVICE_ALL_ACCESS);
    
	if (SCService != NULL)
	{
		
		CloseHandle(driverHandle); 
		driverHandle = NULL; 

		if(!ControlService(SCService, SERVICE_CONTROL_STOP, &status))
			retCode = DRV_ERROR_STOPPING;

		else
			retCode = DRV_SUCCESS;
	}

	else
		retCode = DRV_ERROR_SERVICE;


    CloseServiceHandle(SCService);
	SCService = NULL;

	CloseServiceHandle(SCManager);
	SCManager = NULL;


	if(retCode == DRV_SUCCESS)
		started = FALSE;

    return retCode;
}
Пример #18
0
//suppression du driver (apres stop)
bool remove_driver()
{
	if(!manager)
		manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager)
		return false;

	if(!service)
		service=OpenServiceA( manager, "conixsamdump",  SERVICE_ALL_ACCESS);
	if(!service)
		return false;
	
    if (! DeleteService(service) )
        return false;
    
	return true;
}
Пример #19
0
//suppression du driver (apres stop)
bool analysis::remove_driver()
{
	if(!manager)
		manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager)
		return false;

	if(!service)
		service=OpenServiceA( manager, "hookrevealer",  SERVICE_ALL_ACCESS);
	if(!service)
		return false;
	
    if (! DeleteService(service) )
        return false;
    
	return true;
}
Пример #20
0
bool start_service()
{
	if(!manager)
		manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if(!manager)
		return false;
	
	if(!service)
		service = OpenServiceA( manager, "conixsamdump",  SERVICE_ALL_ACCESS);
	if (!service)
		return false;

	if(!StartServiceA(service, 0, NULL))
		return false;

	return true;
}
Пример #21
0
bool analysis::start_service()
{
	if(!manager)
		manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if(!manager)
		return false;
	
	if(!service)
		service = OpenServiceA( manager, "hookrevealer",  SERVICE_ALL_ACCESS);
	if (!service)
		return false;

	if(!StartServiceA(service, 0, NULL))
		return false;

	return true;
}
Пример #22
0
int cw_uninstallservice(const char *name, int verbose)
{
    SC_HANDLE sm, svc;
    int ret = 1;

    if (!(sm = OpenSCManagerA(NULL, NULL, DELETE)))
    {
        if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
            fprintf(stderr, "Windows Services are not supported on this Platform\n");
        else
            fprintf(stderr, "Unable to Open SCManager (%d)\n", GetLastError());
        return 0;
    }

    if ((svc = OpenServiceA(sm, name, DELETE)))
    {
        if (DeleteService(svc))
        {
            if (verbose) printf("Service %s successfully removed\n", name);
        }
        else
        {
            fprintf(stderr, "Unable to Open Service %s (%d)\n", name, GetLastError());
            ret = 0;
        }
    }
    else
    {
        if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
        {
            if (verbose) printf("Service %s does not exist\n", name);
        }
        else
        {
            fprintf(stderr, "Unable to Open Service %s (%d)\n", name, GetLastError());
            ret = 0;
        }
    }

    if (svc) CloseServiceHandle(svc);
    CloseServiceHandle(sm);
    return ret;
}
Пример #23
0
//stop du service
bool analysis::stop_service()
{
	SERVICE_STATUS useless;

	if(!manager)
		manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager)
		return false;

	if(!service)
		service = OpenServiceA( manager, "hookrevealer",   SERVICE_STOP);

	if(!service)
		return false;
	
	if(!ControlService(service, SERVICE_CONTROL_STOP, &useless))
		return false;

	return true;
}
Пример #24
0
// Returns true if started or already running, false if failed or not installed
static bool startWindowsService()
{
	SERVICE_STATUS ssSvcStatus;
	SC_HANDLE schSCManager = NULL;
	SC_HANDLE schService = NULL;

	schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
	if (schSCManager == NULL)
		return false;

	schService = OpenServiceA(schSCManager, ZT_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START);
	if (schService == NULL) {
		CloseServiceHandle(schSCManager);
		return false;
	}

	int tries = 0;
	bool running = true;

	for(;;) {
		memset(&ssSvcStatus,0,sizeof(ssSvcStatus));
		if ((++tries > 20)||(!QueryServiceStatus(schService,&ssSvcStatus))) {
			running = false;
			break;
		}

		if (ssSvcStatus.dwCurrentState == SERVICE_RUNNING) {
			break;
		} else if (ssSvcStatus.dwCurrentState == SERVICE_START_PENDING) {
			Sleep(500);
			continue;
		}

		StartService(schService,0,NULL);
		Sleep(500);
	}

	CloseServiceHandle(schService);
	CloseServiceHandle(schSCManager);
	return running;
}
Пример #25
0
int analysis::driverStatus()
{
	DWORD dwBytes;
	SERVICE_STATUS_PROCESS status;

	if(!manager)
		manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
	if(!manager)
		return 0;
	
	if(!service)
		service=OpenServiceA( manager, "hookrevealer",  SERVICE_ALL_ACCESS);
	if(!service)
		return DRIVER_NOT_INSTALLED;
	
	if(!QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO, (LPBYTE)&status, sizeof(SERVICE_STATUS_PROCESS), &dwBytes))
		return 0;

	if(status.dwCurrentState == SERVICE_STOPPED || status.dwCurrentState == SERVICE_STOP_PENDING)
		return DRIVER_STOPPED;

	return DRIVER_STARTED;
}
Пример #26
0
static int NTServiceUninstall( intf_thread_t *p_intf )
{
    intf_sys_t *p_sys  = p_intf->p_sys;

    SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
    if( handle == NULL )
    {
        msg_Err( p_intf,
                 "could not connect to Services Control Manager database" );
        return VLC_EGENERIC;
    }

    /* First, open a handle to the service */
    SC_HANDLE service = OpenServiceA( handle, p_sys->psz_service, DELETE );
    if( service == NULL )
    {
        msg_Err( p_intf, "could not open service" );
        CloseServiceHandle( handle );
        return VLC_EGENERIC;
    }

    /* Remove the service */
    if( !DeleteService( service ) )
    {
        msg_Err( p_intf, "could not delete service \"%s\"",
                 p_sys->psz_service );
    }
    else
    {
        msg_Dbg( p_intf, "service deleted successfuly" );
    }

    CloseServiceHandle( service );
    CloseServiceHandle( handle );

    return VLC_SUCCESS;
}
Пример #27
0
void vStopService(void)
{
	SC_HANDLE scmHandle = OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

	if (scmHandle == NULL) // Perform error handling.
	{
		WriteLog(sLogFile, "(%d)서비스 매니저와 연결하는데, 오류가 발생하였습니다.\n", GetLastError() );
		return;
	}

	SC_HANDLE scHandle = OpenServiceA( scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS );

	SERVICE_STATUS ss;

	ss.dwServiceType				= SERVICE_WIN32_OWN_PROCESS;
	ss.dwCurrentState				= SERVICE_STOP_PENDING;
	ss.dwControlsAccepted			= 0;
	ss.dwWin32ExitCode				= 0;
	ss.dwServiceSpecificExitCode	= 0;
	ss.dwCheckPoint					= 0;
	ss.dwWaitHint					= 0;

	ControlService(scHandle,SERVICE_CONTROL_STOP,&ss);

	Sleep (2000);

	do
	{
		ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
		Sleep (100);
	} while (ss.dwCurrentState == SERVICE_STOP_PENDING);

	CloseServiceHandle(scHandle);

	return;
}
Пример #28
0
int
_tmain (int argc, char *argv[])
{
  bool rc;

  // Install a Service if -i switch used
  if (argc == 2)
    {
      if (_stricmp (argv[1], "-u") == 0)
	{
	  vDelService ();
	}
      else if (_stricmp (argv[1], "-start") == 0)
	{
	  vStartService ();
	}
      else if (_stricmp (argv[1], "-stop") == 0)
	{
	  vStopService ();
	}
      else if (_stricmp (argv[1], "-status") == 0)
	{
	  vPrintServiceStatus ();
	}
      else
	WriteLog (sLogFile, "Invalid Argument.\n");
    }
  else if (argc == 3)
    {
      if (_stricmp (argv[1], "-i") == 0)
	{
	  if (strlen (argv[2]) > 0)
	    strcpy_s (sExecPath, argv[2]);

	  vctrlService ();
	}
      else
	{
	  SERVICE_STATUS ss;
	  int service_control_code;

	  SC_HANDLE scmHandle =
	    OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

	  if (scmHandle == NULL)	// Perform error handling.
	    {
	      WriteLog (sLogFile,
			"(%d)Cannot connect to the Windows Service Control Manager.\n",
			GetLastError ());
	      return 0;
	    }

	  SC_HANDLE scHandle =
	    OpenServiceA (scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS);

	  if (_stricmp (argv[1], CUBRID_UTIL_SERVICE) == 0)
	    {
	      if (_stricmp (argv[2], CUBRID_COMMAND_START) == 0)
		{
		  service_control_code = SERVICE_CONTROL_SERVICE_START;
		}
	      else if (_stricmp (argv[2], CUBRID_COMMAND_STOP) == 0)
		{
		  service_control_code = SERVICE_CONTROL_SERVICE_STOP;
		}
	      else
		{
		  WriteLog (sLogFile, "Invalid Argument.\n");
		  CloseServiceHandle (scHandle);
		  CloseServiceHandle (scmHandle);
		  return 0;
		}
	    }
	  else if (_stricmp (argv[1], CUBRID_UTIL_BROKER) == 0)
	    {
	      if (_stricmp (argv[2], CUBRID_COMMAND_START) == 0)
		{
		  service_control_code = SERVICE_CONTROL_BROKER_START;
		}
	      else if (_stricmp (argv[2], CUBRID_COMMAND_STOP) == 0)
		{
		  service_control_code = SERVICE_CONTROL_BROKER_STOP;
		}
	      else
		{
		  WriteLog (sLogFile, "Invalid Argument.\n");
		  CloseServiceHandle (scHandle);
		  CloseServiceHandle (scmHandle);
		  return 0;
		}
	    }
	  else if (_stricmp (argv[1], CUBRID_UTIL_SHARD) == 0)
	    {
	      if (_stricmp (argv[2], CUBRID_COMMAND_START) == 0)
		{
		  service_control_code = SERVICE_CONTROL_SHARD_START;
		}
	      else if (_stricmp (argv[2], CUBRID_COMMAND_STOP) == 0)
		{
		  service_control_code = SERVICE_CONTROL_SHARD_STOP;
		}
	      else
		{
		  WriteLog (sLogFile, "Invalid Argument.\n");
		  CloseServiceHandle (scHandle);
		  CloseServiceHandle (scmHandle);
		  return 0;
		}
	    }
	  else if (_stricmp (argv[1], CUBRID_UTIL_MANAGER) == 0)
	    {
	      if (_stricmp (argv[2], CUBRID_COMMAND_START) == 0)
		{
		  service_control_code = SERVICE_CONTROL_MANAGER_START;
		}
	      else if (_stricmp (argv[2], CUBRID_COMMAND_STOP) == 0)
		{
		  service_control_code = SERVICE_CONTROL_MANAGER_STOP;
		}
	      else
		{
		  WriteLog (sLogFile, "Invalid Argument.\n");
		  CloseServiceHandle (scHandle);
		  CloseServiceHandle (scmHandle);
		  return 0;
		}
	    }
	  else
	    {
	      WriteLog (sLogFile, "Invalid Argument.\n");
	      CloseServiceHandle (scHandle);
	      CloseServiceHandle (scmHandle);
	      return 0;
	    }

	  ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
	  if (ss.dwCurrentState == SERVICE_STOPPED)
	    {
	      LPCTSTR argv[2] =
		{ "CUBRIDService", "--dont-start-cubrid-process" };

	      if (service_control_code == SERVICE_CONTROL_SERVICE_STOP)
		{
		  CloseServiceHandle (scHandle);
		  CloseServiceHandle (scmHandle);
		  return 0;
		}

	      StartService (scHandle, 2, argv);
	      Sleep (2000);

	      do
		{
		  ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
		  Sleep (100);
		}
	      while (ss.dwCurrentState == SERVICE_START_PENDING);
	    }

	  // send control code
	  rc = ControlService (scHandle, service_control_code, &ss);
	  if (!rc && ss.dwCurrentState == SERVICE_RUNNING
	      && GetLastError () == ERROR_SERVICE_REQUEST_TIMEOUT)
	    {
	      if (!ControlService
		  (scHandle, SERVICE_CONTROL_INTERROGATE, &ss))
		{
		  WriteLog (sLogFile,
			    "ControlService error. check status manually.\n");
		}
	    }
	  CloseServiceHandle (scHandle);
	  CloseServiceHandle (scmHandle);
	}
    }
  else if (argc == 4)
    {
      if (_stricmp (argv[1], CUBRID_UTIL_SERVER) == 0 ||
	  _stricmp (argv[1], CUBRID_UTIL_BROKER) == 0)
	{
	  SERVICE_STATUS ss;
	  int service_control_code;

	  SC_HANDLE scmHandle =
	    OpenSCManager (NULL, NULL, SC_MANAGER_ALL_ACCESS);

	  if (scmHandle == NULL)	// Perform error handling.
	    {
	      WriteLog (sLogFile,
			"(%d)Cannot connect to the Windows Service Control Manager.\n",
			GetLastError ());
	      return 0;
	    }

	  SC_HANDLE scHandle =
	    OpenServiceA (scmHandle, "CUBRIDService", SERVICE_ALL_ACCESS);
	  if (_stricmp (argv[1], CUBRID_UTIL_SERVER) == 0 &&
	      _stricmp (argv[2], CUBRID_COMMAND_START) == 0)
	    {
	      service_control_code = SERVICE_CONTROL_SERVER_START;
	    }
	  else if (_stricmp (argv[1], CUBRID_UTIL_SERVER) == 0 &&
		   _stricmp (argv[2], CUBRID_COMMAND_STOP) == 0)
	    {
	      service_control_code = SERVICE_CONTROL_SERVER_STOP;
	    }
	  else if (_stricmp (argv[1], CUBRID_UTIL_BROKER) == 0 &&
		   _stricmp (argv[2], CUBRID_COMMAND_ON) == 0)
	    {
	      service_control_code = SERVICE_CONTROL_BROKER_ON;
	    }
	  else if (_stricmp (argv[1], CUBRID_UTIL_BROKER) == 0 &&
		   _stricmp (argv[2], CUBRID_COMMAND_OFF) == 0)
	    {
	      service_control_code = SERVICE_CONTROL_BROKER_OFF;
	    }
	  else
	    {
	      WriteLog (sLogFile, "Invalid Argument.\n");
	      CloseServiceHandle (scHandle);
	      CloseServiceHandle (scmHandle);
	      return 0;
	    }

	  ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
	  if (ss.dwCurrentState == SERVICE_STOPPED)
	    {
	      LPCTSTR argv[2] =
		{ "CUBRIDService", "--dont-start-cubrid-process" };
	      StartService (scHandle, 2, argv);
	      Sleep (2000);

	      do
		{
		  ControlService (scHandle, SERVICE_CONTROL_INTERROGATE, &ss);
		  Sleep (100);
		}
	      while (ss.dwCurrentState == SERVICE_START_PENDING);
	    }

	  char *db_name = TEXT (argv[3]);
	  if (write_string_value_in_registry (HKEY_LOCAL_MACHINE,
					      "SOFTWARE\\CUBRID\\CUBRID",
					      "CUBRID_DBNAME_FOR_SERVICE",
					      db_name) == false)
	    {
	      WriteLog (sLogFile, "write_string_value_in_registry error.\n");

	      CloseServiceHandle (scHandle);
	      CloseServiceHandle (scmHandle);

	      return 0;
	    }

	  // send control code
	  rc = ControlService (scHandle, service_control_code, &ss);
	  if (!rc && ss.dwCurrentState == SERVICE_RUNNING
	      && GetLastError () == ERROR_SERVICE_REQUEST_TIMEOUT)
	    {
	      if (!ControlService
		  (scHandle, SERVICE_CONTROL_INTERROGATE, &ss))
		{
		  WriteLog (sLogFile,
			    "ControlService error. check status manually.\n");
		}
	    }
	  CloseServiceHandle (scHandle);
	  CloseServiceHandle (scmHandle);
	}
    }
  else
    WriteLog (sLogFile, "Invalid Argument.\n");

  return 0;
}
Пример #29
0
static void test_install_svc_from(void)
{
    char inf[2048];
    char path[MAX_PATH];
    HINF infhandle;
    BOOL ret;
    SC_HANDLE scm_handle, svc_handle;

    /* Bail out if we are on win98 */
    SetLastError(0xdeadbeef);
    scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);

    if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
    {
        win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
        return;
    }
    CloseServiceHandle(scm_handle);

    /* Basic inf file to satisfy SetupOpenInfFileA */
    strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
    create_inf_file(inffile, inf);
    sprintf(path, "%s\\%s", CURR_DIR, inffile);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);

    /* Nothing but the Version section */
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
        "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* Add the section */
    strcat(inf, "[Winetest.Services]\n");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_SECTION_NOT_FOUND,
        "Expected ERROR_SECTION_NOT_FOUND, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* Add a reference */
    strcat(inf, "AddService=Winetest,,Winetest.Service\n");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
        "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* Add the section */
    strcat(inf, "[Winetest.Service]\n");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
        "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* Just the ServiceBinary */
    strcat(inf, "ServiceBinary=%12%\\winetest.sys\n");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
        "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* Add the ServiceType */
    strcat(inf, "ServiceType=1\n");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
        "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* Add the StartType */
    strcat(inf, "StartType=4\n");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    ok(!ret, "Expected failure\n");
    ok(GetLastError() == ERROR_BAD_SERVICE_INSTALLSECT,
        "Expected ERROR_BAD_SERVICE_INSTALLSECT, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* This should be it, the minimal entries to install a service */
    strcat(inf, "ErrorControl=1");
    create_inf_file(inffile, inf);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);
    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "Winetest.Services", 0);
    if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
    {
        skip("Not enough rights to install the service\n");
        SetupCloseInfFile(infhandle);
        DeleteFileA(inffile);
        return;
    }
    ok(ret, "Expected success\n");
    ok(GetLastError() == ERROR_SUCCESS,
        "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);

    /* Open the service to see if it's really there */
    svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
    ok(svc_handle != NULL, "Service was not created\n");

    SetLastError(0xdeadbeef);
    ret = DeleteService(svc_handle);
    ok(ret, "Service could not be deleted : %d\n", GetLastError());

    CloseServiceHandle(svc_handle);
    CloseServiceHandle(scm_handle);

    strcpy(inf, "[Version]\nSignature=\"$Chicago$\"\n");
    strcat(inf, "[XSP.InstallPerVer]\n");
    strcat(inf, "AddReg=AspEventlogMsg.Reg,Perf.Reg,AspVersions.Reg,FreeADO.Reg,IndexServer.Reg\n");
    create_inf_file(inffile, inf);
    sprintf(path, "%s\\%s", CURR_DIR, inffile);
    infhandle = SetupOpenInfFileA(path, NULL, INF_STYLE_WIN4, NULL);

    SetLastError(0xdeadbeef);
    ret = SetupInstallServicesFromInfSectionA(infhandle, "XSP.InstallPerVer", 0);
    ok(ret, "Expected success\n");
    ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %08x\n", GetLastError());
    SetupCloseInfFile(infhandle);
    DeleteFileA(inffile);

    /* TODO: Test the Flags */
}
Пример #30
0
static void test_driver_install(void)
{
    HANDLE handle;
    SC_HANDLE scm_handle, svc_handle;
    BOOL ret;
    char path[MAX_PATH], windir[MAX_PATH], driver[MAX_PATH];
    DWORD attrs;
    /* Minimal stuff needed */
    static const char *inf =
        "[Version]\n"
        "Signature=\"$Chicago$\"\n"
        "[DestinationDirs]\n"
        "Winetest.DriverFiles=12\n"
        "[DefaultInstall]\n"
        "CopyFiles=Winetest.DriverFiles\n"
        "[DefaultInstall.Services]\n"
        "AddService=Winetest,,Winetest.Service\n"
        "[Winetest.Service]\n"
        "ServiceBinary=%12%\\winetest.sys\n"
        "ServiceType=1\n"
        "StartType=4\n"
        "ErrorControl=1\n"
        "[Winetest.DriverFiles]\n"
        "winetest.sys";

    /* Bail out if we are on win98 */
    SetLastError(0xdeadbeef);
    scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);

    if (!scm_handle && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
    {
        win_skip("OpenSCManagerA is not implemented, we are most likely on win9x\n");
        return;
    }
    else if (!scm_handle && (GetLastError() == ERROR_ACCESS_DENIED))
    {
        skip("Not enough rights to install the service\n");
        return;
    }
    CloseServiceHandle(scm_handle);

    /* Place where we expect the driver to be installed */
    GetWindowsDirectoryA(windir, MAX_PATH);
    lstrcpyA(driver, windir);
    lstrcatA(driver, "\\system32\\drivers\\winetest.sys");

    /* Create a dummy driver file */
    handle = CreateFileA("winetest.sys", GENERIC_WRITE, 0, NULL,
                           CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    CloseHandle(handle);

    create_inf_file(inffile, inf);
    sprintf(path, "%s\\%s", CURR_DIR, inffile);
    run_cmdline("DefaultInstall", 128, path);

    /* Driver should have been installed */
    attrs = GetFileAttributesA(driver);
    ok(attrs != INVALID_FILE_ATTRIBUTES, "Expected driver to exist\n");

    scm_handle = OpenSCManagerA(NULL, NULL, GENERIC_ALL);

    /* Open the service to see if it's really there */
    svc_handle = OpenServiceA(scm_handle, "Winetest", DELETE);
    ok(svc_handle != NULL, "Service was not created\n");

    SetLastError(0xdeadbeef);
    ret = DeleteService(svc_handle);
    ok(ret, "Service could not be deleted : %d\n", GetLastError());

    CloseServiceHandle(svc_handle);
    CloseServiceHandle(scm_handle);

    /* File cleanup */
    DeleteFileA(inffile);
    DeleteFileA("winetest.sys");
    DeleteFileA(driver);
}