|
장성호님 도움을 많이 받네요...
상세한 답변 감사드립니다.
장성호 님이 쓰신 글 :
: 방법1 . Process를 찾아서 TerminateProcess로 삭제하면 됩니다.
: Process를 찾는 함수는 FindProcess로 검색해 보세요
: 다시 실행은 WinExec
:
: 방법2. 윈도우 서비스에 등록했다고 말씀하셨으니까
: 서비스관련 API를 이용하는 방법이있습니다.
: 내가등록한 서비스가 제대로 등록되어있는지
: 현재 상태는 어떤지...
:
: 아래 코드를 참조해 보세요
:
:
: BOOL RemoveService(String sSrvName)
: {
: SC_HANDLE schService = NULL;
:
: SC_HANDLE schSCManager = NULL;
:
: TCHAR szError[MAX_PATH] = {0, };
:
: BOOL bRet = FALSE;
:
: schSCManager = ::OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS );
: if ( NULL != schSCManager )
: {
: schService = ::OpenService(schSCManager,sSrvName.c_str(),SERVICE_ALL_ACCESS);
: if (NULL != schService)
: {
: if (TRUE == ::ControlService(schService,SERVICE_CONTROL_STOP, &g_sStatus))
: {
: while( ::QueryServiceStatus( schService, &g_sStatus) )
: {
: if (g_sStatus.dwCurrentState == SERVICE_STOP_PENDING )
: {
: ::Sleep( 1000 );
: }
: else
: {
: break;
: }
:
: }
: if (g_sStatus.dwCurrentState == SERVICE_STOPPED )
: {
: ShowMessage(sSrvName+" Stop \n");
: bRet = TRUE;
: }
: else
: {
: ShowMessage(sSrvName+" failed \n");
: bRet = FALSE;
: }
: }
: if( TRUE == ::DeleteService(schService) )
: {
: ShowMessage(sSrvName+" removed \n");
: //printf("MySql removed \n");
: bRet = TRUE;
: }
: else
: {
: ShowMessage(sSrvName+" DeleteService failed \n");
: //printf("MySql DeleteService failed \n");
: bRet = FALSE;
: }
: ::CloseServiceHandle(schService);
: }
: else
: {
: ShowMessage(sSrvName+" OpenService failed \n");
: //printf("MySql OpenService failed \n");
: bRet = FALSE;
:
: }
: ::CloseServiceHandle(schSCManager);
: }
: else
: {
: ShowMessage(sSrvName+" OpenSCManager failed \n");
: //printf("MySql OpenSCManager failed \n");
: bRet = FALSE;
: }
: return bRet;
: }
: //---------------------------------------------------------------------------
: void __fastcall StartService(String sSrvName)
: {
: SC_HANDLE hScm,hSrv;
: SERVICE_STATUS ss;
:
: hScm=OpenSCManager(NULL,NULL,GENERIC_READ);
: hSrv=OpenService(hScm,sSrvName.c_str(),SERVICE_START| SERVICE_QUERY_STATUS);//AMR_IP_SER.exe//AMR Remote IP Server
:
: ::SetCursor(LoadCursor(NULL,IDC_WAIT));
: if(StartService(hSrv,0,NULL)==TRUE)
: {
: QueryServiceStatus(hSrv,&ss);
: while(ss.dwCurrentState != SERVICE_RUNNING)
: {
: Sleep(ss.dwWaitHint);
: QueryServiceStatus(hSrv,&ss);
: }
: }
: else
: {
: //
: hSrv=OpenService(hScm,sSrvName.c_str(),SERVICE_CONTROL_INTERROGATE);
:
: ControlService(hSrv,SERVICE_CONTROL_INTERROGATE,&ss);
: if(ss.dwCurrentState==SERVICE_PAUSED)
: {
: hSrv=OpenService(hScm,sSrvName.c_str(),GENERIC_EXECUTE);
: ControlService(hSrv,SERVICE_CONTROL_CONTINUE,&ss);
:
: }
: }
: ::SetCursor(LoadCursor(NULL,IDC_ARROW));
: CloseServiceHandle(hSrv);
: // QueryService();
: }
|