C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[71634] Re:Re:Windows Service 목록 조회
비베시러 [] 3699 읽음    2014-08-04 13:09

답변감사합니다.

Windows API로 접근할 생각은 안하고,
BDS에서 지원하는 것으로만 찾았네요.

다시한번 감사드립니다.


둘리.CSIEDA 님이 쓰신 글 :
: RetrieveAllServices 이함수에 메모장 Lines 보내시면 메모장에 서비스들 나열 됩니다.
:
: Service Status 에 대한 것은 _SERVICE_STATUS 이 구조를 보시면되고
:
: http://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx
:
: 여기 보시만 아시겠죠?
:
:
: ㅠㅠ.. 구글링하면 많이 나오네요...
:
:
: #include <windows.h>
: #include <iostream.h>
:
: void ErrorDescription(DWORD p_dwError);
:
: int RetrieveAllServices(TStrings *msgout)
: {
:     SC_HANDLE hHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
:
:     if (NULL == hHandle) {
:         ErrorDescription(GetLastError());
:         return -1;
:     }
:     else {
:         //cout << "Open SCM sucessfully" << endl;
:         msgout->Add("Open SCM successfully");
:     }
:
:     ENUM_SERVICE_STATUS service;
:
:     DWORD dwBytesNeeded = 0;
:     DWORD dwServicesReturned = 0;
:     DWORD dwResumedHandle = 0;
:     DWORD dwServiceType = SERVICE_WIN32 | SERVICE_DRIVER;
:
:     // Query services
:     BOOL retVal = EnumServicesStatus(hHandle, dwServiceType, SERVICE_STATE_ALL,
:         &service, sizeof(ENUM_SERVICE_STATUS), &dwBytesNeeded, &dwServicesReturned,
:         &dwResumedHandle);
:
:     if (!retVal) {
:         // Need big buffer
:         if (ERROR_MORE_DATA == GetLastError()) {
:             // Set the buffer
:             DWORD dwBytes = sizeof(ENUM_SERVICE_STATUS) + dwBytesNeeded;
:             ENUM_SERVICE_STATUS* pServices = NULL;
:             pServices = new ENUM_SERVICE_STATUS [dwBytes];
:
:             // Now query again for services
:             EnumServicesStatus(hHandle, SERVICE_WIN32 | SERVICE_DRIVER, SERVICE_STATE_ALL,
:                 pServices, dwBytes, &dwBytesNeeded, &dwServicesReturned, &dwResumedHandle);
:
:             // now traverse each service to get information
:             for (unsigned iIndex = 0; iIndex < dwServicesReturned; iIndex++) {
:
:                 msgout->Add(AnsiString("Display Name : ")+ (pServices + iIndex)->lpDisplayName);
:                 msgout->Add(AnsiString("Service Name : ")+ (pServices + iIndex)->lpServiceName);
:                 msgout->Add(AnsiString("Current Status : ")+ (pServices + iIndex)->ServiceStatus.dwCurrentState);
:             }
:
:             delete [] pServices;
:             pServices = NULL;
:
:         }
:         // there is any other reason
:         else {
:             ErrorDescription(GetLastError());
:         }
:     }
:
:     if (!CloseServiceHandle(hHandle)) {
:         ErrorDescription(GetLastError());
:     }
:     else {
:         //cout << "Close SCM sucessfully" << endl;
:         msgout->Add("Close SCM successfully");
:
:     }
:
:     return 0;
: }
:
: // get the description of error
: void ErrorDescription(DWORD p_dwError) {
:
:     HLOCAL hLocal = NULL;
:
:     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER,
:         NULL, p_dwError, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),(LPTSTR)&hLocal,
:         0, NULL);
:
:     MessageBox(NULL, (LPCTSTR)LocalLock(hLocal), TEXT("Error"), MB_OK | MB_ICONERROR);
:     LocalFree(hLocal);
: }
:
:
:
:
: 비베시러 님이 쓰신 글 :
: : 안녕하세요
: :
: : 윈도우의 서비스로 구동되고 있는 list를 조회하고 싶습니다.
: : (감시 프로그램을 만들고 싶어서요)
: :
: : 프로그램에서 특정 Process가 구동되는지 확인하고 싶은데요
: :
: : C#의 경우
: :
: : using System.ServiceProcess; 를 통해서
: : 
: : ServiceController service in ServiceController.GetServices() 내에
: :
: : string serviceName = service.ServiceName;  으로 이름을 얻어 올 수 있고
: :
: : string status = service.Status.ToString(); 로 Run/Stop 상태까지 알수 있으나,
: :
: : C++ 빌더에서는 어떻게 해야 하는지 궁금합니다. 
: :
: : 혹시 TProcess를 통해서 가능한지? 아시는분의 도움을 구합니다.
: : 구글을 찾아봐도 마땅한 내용이 없어서 글 올립니다.
: :
: :
: :
: :

+ -

관련 글 리스트
71631 Windows Service 목록 조회 비베시러 3525 2014/08/04
71632     Re:Windows Service 목록 조회 둘리.CSIEDA 3785 2014/08/04
71634         Re:Re:Windows Service 목록 조회 비베시러 3699 2014/08/04
71635             Re:Re:Re:Windows Service 목록 조회 비베시러 3543 2014/08/04
71636                 Re:Re:Re:Re:Windows Service 목록 조회 둘리.CSIEDA 3662 2014/08/04
71659                     Re:Re:Re:Re:Re:Windows Service 목록 조회 비배시러 3681 2014/08/09
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.