--- /dev/null
+#include "servman.h"\r
+\r
+extern HINSTANCE hInstance;\r
+extern HWND hListView;\r
+extern HWND hStatus;\r
+\r
+/* Stores the service array */\r
+ENUM_SERVICE_STATUS_PROCESS *pServiceStatus = NULL;\r
+\r
+\r
+/* free service array */\r
+VOID FreeMemory(VOID)\r
+{\r
+ HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
+}\r
+\r
+\r
+BOOL\r
+RefreshServiceList(VOID)\r
+{\r
+ LV_ITEM item;\r
+ TCHAR szNumServices[32];\r
+ TCHAR szStatus[128];\r
+ DWORD NumServices = 0;\r
+ DWORD Index;\r
+\r
+ NumServices = GetServiceList();\r
+\r
+ if (NumServices)\r
+ {\r
+ HICON hiconItem; /* icon for list-view items */\r
+ HIMAGELIST hSmall; /* image list for other views */\r
+ TCHAR buf[40];\r
+\r
+ /* Create the icon image lists */\r
+ hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),\r
+ GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1);\r
+\r
+ /* Add an icon to each image list */\r
+ hiconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0);\r
+ ImageList_AddIcon(hSmall, hiconItem);\r
+\r
+ ListView_SetImageList(hListView, hSmall, LVSIL_SMALL);\r
+\r
+ /* set the number of services in the status bar */\r
+ LoadString(hInstance, IDS_SERVICES_NUM_SERVICES, szNumServices, 32);\r
+ _stprintf(buf, szNumServices, NumServices);\r
+ SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf);\r
+\r
+ for (Index = 0; Index < NumServices; Index++)\r
+ {\r
+ HKEY hKey = NULL;\r
+ TCHAR Description[5000];\r
+ DWORD Size = 5000;\r
+\r
+ /* set the display name */\r
+\r
+ ZeroMemory(&item, sizeof(LV_ITEM));\r
+ item.mask = LVIF_TEXT;\r
+ //item.iImage = 0;\r
+ item.pszText = pServiceStatus[Index].lpDisplayName;\r
+ item.iItem = ListView_GetItemCount(hListView);\r
+ item.lParam = 0;\r
+ item.iItem = ListView_InsertItem(hListView, &item);\r
+\r
+\r
+ /* set the description */\r
+\r
+ _stprintf(buf, _T("System\\CurrentControlSet\\Services\\%s"),\r
+ pServiceStatus[Index].lpServiceName);\r
+\r
+ if( RegOpenKeyEx(HKEY_LOCAL_MACHINE,\r
+ buf,\r
+ 0,\r
+ KEY_READ,\r
+ &hKey) != ERROR_SUCCESS)\r
+ {\r
+ GetError();\r
+ return FALSE;\r
+ }\r
+\r
+ RegQueryValueEx(hKey,\r
+ _T("Description"),\r
+ NULL,\r
+ NULL,\r
+ (LPBYTE)Description,\r
+ &Size);\r
+\r
+ item.pszText = Description;\r
+ item.iSubItem = 1;\r
+ SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+\r
+\r
+ /* set the status */\r
+\r
+ if (pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)\r
+ {\r
+ LoadString(hInstance, IDS_SERVICES_STATUS_RUNNING, szStatus, 128);\r
+ item.pszText = szStatus;\r
+ item.iSubItem = 2;\r
+ SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+ }\r
+ else\r
+ {\r
+ item.pszText = '\0';\r
+ item.iSubItem = 2;\r
+ SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+ }\r
+ }\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+\r
+\r
+\r
+DWORD\r
+GetServiceList(VOID)\r
+{\r
+ SC_HANDLE ScHandle;\r
+\r
+ DWORD BytesNeeded = 0;\r
+ DWORD ResumeHandle = 0;\r
+ DWORD NumServices = 0;\r
+\r
+ ScHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);\r
+ if (ScHandle != INVALID_HANDLE_VALUE)\r
+ {\r
+ if (EnumServicesStatusEx(ScHandle,\r
+ SC_ENUM_PROCESS_INFO,\r
+ SERVICE_WIN32,\r
+ SERVICE_STATE_ALL,\r
+ (LPBYTE)pServiceStatus,\r
+ 0, &BytesNeeded,\r
+ &NumServices,\r
+ &ResumeHandle,\r
+ 0) == 0)\r
+ {\r
+ /* Call function again if required size was returned */\r
+ if (GetLastError() == ERROR_MORE_DATA)\r
+ {\r
+ /* reserve memory for service info array */\r
+ pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
+ if (pServiceStatus == NULL)\r
+ return FALSE;\r
+\r
+ /* fill array with service info */\r
+ if (EnumServicesStatusEx(ScHandle,\r
+ SC_ENUM_PROCESS_INFO,\r
+ SERVICE_WIN32,\r
+ SERVICE_STATE_ALL,\r
+ (LPBYTE)pServiceStatus,\r
+ BytesNeeded,\r
+ &BytesNeeded,\r
+ &NumServices,\r
+ &ResumeHandle,\r
+ 0) == 0)\r
+ {\r
+ HeapFree(GetProcessHeap(), 0, pServiceStatus);\r
+ return FALSE;\r
+ }\r
+ }\r
+ else /* exit on failure */\r
+ {\r
+ return FALSE;\r
+ }\r
+ }\r
+ }\r
+\r
+ CloseServiceHandle(ScHandle);\r
+\r
+ return NumServices;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+/*\r
+ //WORD wCodePage;\r
+ //WORD wLangID;\r
+ //SC_HANDLE hService;\r
+ //DWORD dwHandle, dwLen;\r
+ //UINT BufLen;\r
+ //TCHAR* lpData;\r
+ //TCHAR* lpBuffer;\r
+ //TCHAR szStrFileInfo[80];\r
+ //TCHAR FileName[MAX_PATH];\r
+ //LPVOID pvData;\r
+\r
+ //LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;\r
+ //LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;\r
+\r
+ BytesNeeded = 0;\r
+ hService = OpenService(ScHandle,\r
+ pServiceStatus[Index].lpServiceName,\r
+ SC_MANAGER_CONNECT);\r
+ if (hService != INVALID_HANDLE_VALUE)\r
+ {\r
+ / * check if service is required by the system* /\r
+ if (!QueryServiceConfig2(hService,\r
+ SERVICE_CONFIG_FAILURE_ACTIONS,\r
+ (LPBYTE)pServiceFailureActions,\r
+ 0,\r
+ &BytesNeeded))\r
+ {\r
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
+ {\r
+ pServiceFailureActions = (LPSERVICE_FAILURE_ACTIONS)\r
+ HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
+ if (pServiceFailureActions == NULL)\r
+ return FALSE;\r
+\r
+ if (!QueryServiceConfig2(hService,\r
+ SERVICE_CONFIG_FAILURE_ACTIONS,\r
+ (LPBYTE)pServiceFailureActions,\r
+ BytesNeeded,\r
+ &BytesNeeded))\r
+ {\r
+ HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
+ return FALSE;\r
+ }\r
+ }\r
+ else / * exit on failure * /\r
+ {\r
+ return FALSE;\r
+ }\r
+ }\r
+ if (pServiceFailureActions->cActions)\r
+ {\r
+ if (pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)\r
+ {\r
+ LoadString(hInstance, IDS_SERVICES_YES, szStatus, 128);\r
+ item.pszText = szStatus;\r
+ item.iSubItem = 1;\r
+ SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+ }\r
+ }\r
+\r
+ if (pServiceFailureActions != NULL)\r
+ {\r
+ HeapFree(GetProcessHeap(), 0, pServiceFailureActions);\r
+ pServiceFailureActions = NULL;\r
+ }\r
+\r
+ / * get vendor of service binary * /\r
+ BytesNeeded = 0;\r
+ if (!QueryServiceConfig(hService, pServiceConfig, 0, &BytesNeeded))\r
+ {\r
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)\r
+ {\r
+ pServiceConfig = (LPQUERY_SERVICE_CONFIG)\r
+ HeapAlloc(GetProcessHeap(), 0, BytesNeeded);\r
+ if (pServiceConfig == NULL)\r
+ return FALSE;\r
+\r
+ if (!QueryServiceConfig(hService,\r
+ pServiceConfig,\r
+ BytesNeeded,\r
+ &BytesNeeded))\r
+ {\r
+ HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
+ return FALSE;\r
+ }\r
+ }\r
+ else / * exit on failure * /\r
+ {\r
+ return FALSE;\r
+ }\r
+ }\r
+\r
+ memset(&FileName, 0, MAX_PATH);\r
+ if (_tcscspn(pServiceConfig->lpBinaryPathName, _T("\"")))\r
+ {\r
+ _tcsncpy(FileName, pServiceConfig->lpBinaryPathName,\r
+ _tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")) );\r
+ }\r
+ else\r
+ {\r
+ _tcscpy(FileName, pServiceConfig->lpBinaryPathName);\r
+ }\r
+\r
+ HeapFree(GetProcessHeap(), 0, pServiceConfig);\r
+ pServiceConfig = NULL;\r
+\r
+ dwLen = GetFileVersionInfoSize(FileName, &dwHandle);\r
+ if (dwLen)\r
+ {\r
+ lpData = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, dwLen);\r
+ if (lpData == NULL)\r
+ return FALSE;\r
+\r
+ if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData)) {\r
+ HeapFree(GetProcessHeap(), 0, lpData);\r
+ return FALSE;\r
+ }\r
+\r
+ if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))\r
+ {\r
+ wCodePage = LOWORD(*(DWORD*) pvData);\r
+ wLangID = HIWORD(*(DWORD*) pvData);\r
+ wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);\r
+ }\r
+\r
+ if (VerQueryValue (lpData, szStrFileInfo, (LPVOID) &lpBuffer, (PUINT) &BufLen)) {\r
+ item.pszText = lpBuffer;\r
+ item.iSubItem = 2;\r
+ SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+ }\r
+ HeapFree(GetProcessHeap(), 0, lpData);\r
+ }\r
+ else\r
+ {\r
+ LoadString(hInstance, IDS_SERVICES_UNKNOWN, szStatus, 128);\r
+ item.pszText = szStatus;\r
+ item.iSubItem = 2;\r
+ SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);\r
+ }\r
+ CloseServiceHandle(hService);\r
+ }\r
+*/\r