도움 감사드립니다.
많은 도움이 되었습니다.
둘리.CSIEDA 님이 쓰신 글 :
: Windows API 도 BDS API 라 다를게 없습니다.
:
: 어짜피 누군가 BPL package로 만들어봤자.. 윈도우 위에서도는거니 결국 아래와 같은 함수를 호출하는 랩퍼인데
: 굳이 찾으실 필요가 있을까요?
:
:
: Windows API를 BDS가 링크 해주니까 BDS에서 지원 되는것이라 생각 되는데요...
:
:
: 비베시러 님이 쓰신 글 :
: : 한가지 더 질문드리자면
: :
: : C++빌더에서 제공하는 라이브러리나 클래스는 없는지요?
: :
: : C#에서도 지원되는데, BDS에서는 API를 통해서만 가능한지요?
: :
: :
: :
: : 비베시러 님이 쓰신 글 :
: : :
: : : 답변감사합니다.
: : :
: : : 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를 통해서 가능한지? 아시는분의 도움을 구합니다.
: : : : : 구글을 찾아봐도 마땅한 내용이 없어서 글 올립니다.
: : : : :
: : : : :
: : : : :
: : : : :