X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fsubsys%2Fsystem%2Fservman%2Fquery.c;h=523b223770d09ac43fca6287651d91d488d77182;hp=96458353eb40281be5563205d0454fa17b64cf83;hb=9cfeba8d37e1c5fe3458ccedc6fb0d91e8e75682;hpb=e019f1504856ad45dd4cdf5c5698c404ef658c37 diff --git a/reactos/subsys/system/servman/query.c b/reactos/subsys/system/servman/query.c index 96458353eb4..523b223770d 100644 --- a/reactos/subsys/system/servman/query.c +++ b/reactos/subsys/system/servman/query.c @@ -1,3 +1,12 @@ +/* + * PROJECT: ReactOS Services + * LICENSE: GPL - See COPYING in the top level directory + * FILE: subsys/system/servman/query.c + * PURPOSE: Query service information + * COPYRIGHT: Copyright 2005 Ged Murphy + * + */ + #include "servman.h" extern HINSTANCE hInstance; @@ -18,11 +27,14 @@ VOID FreeMemory(VOID) BOOL RefreshServiceList(VOID) { - LV_ITEM item; + LVITEM item; TCHAR szNumServices[32]; TCHAR szStatus[128]; DWORD NumServices = 0; DWORD Index; + LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s"); + + ListView_DeleteAllItems(hListView); NumServices = GetServiceList(); @@ -30,11 +42,11 @@ RefreshServiceList(VOID) { HICON hiconItem; /* icon for list-view items */ HIMAGELIST hSmall; /* image list for other views */ - TCHAR buf[40]; + TCHAR buf[300]; /* Create the icon image lists */ hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), ILC_MASK, 1, 1); + GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR16, 1, 1); /* Add an icon to each image list */ hiconItem = LoadImage(hInstance, MAKEINTRESOURCE(IDI_SM_ICON), IMAGE_ICON, 16, 16, 0); @@ -44,51 +56,90 @@ RefreshServiceList(VOID) /* set the number of services in the status bar */ LoadString(hInstance, IDS_SERVICES_NUM_SERVICES, szNumServices, 32); - _stprintf(buf, szNumServices, NumServices); + _sntprintf(buf, 300, szNumServices, NumServices); SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)buf); + for (Index = 0; Index < NumServices; Index++) { HKEY hKey = NULL; - TCHAR Description[5000]; - DWORD Size = 5000; + LPTSTR Description = NULL; + LONG ret; + LPTSTR LogOnAs = NULL; + DWORD StartUp = 0; + DWORD dwValueSize; + + /* open the registry key for the service */ + _sntprintf(buf, 300, Path, + pServiceStatus[Index].lpServiceName); + + if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, + buf, + 0, + KEY_READ, + &hKey) != ERROR_SUCCESS) + { + GetError(); + return FALSE; + } + /* set the display name */ ZeroMemory(&item, sizeof(LV_ITEM)); item.mask = LVIF_TEXT; - //item.iImage = 0; item.pszText = pServiceStatus[Index].lpDisplayName; item.iItem = ListView_GetItemCount(hListView); - item.lParam = 0; item.iItem = ListView_InsertItem(hListView, &item); + /* set the description */ - - _stprintf(buf, _T("System\\CurrentControlSet\\Services\\%s"), - pServiceStatus[Index].lpServiceName); - - if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, - buf, - 0, - KEY_READ, - &hKey) != ERROR_SUCCESS) + dwValueSize = 0; + ret = RegQueryValueEx(hKey, + _T("Description"), + NULL, + NULL, + NULL, + &dwValueSize); + if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND) { - GetError(); + RegCloseKey(hKey); return FALSE; } + + if (ret != ERROR_FILE_NOT_FOUND) + { + Description = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize); + if (Description == NULL) + { + RegCloseKey(hKey); + return FALSE; + } + if(RegQueryValueEx(hKey, + _T("Description"), + NULL, + NULL, + (LPBYTE)Description, + &dwValueSize)) + { + HeapFree(GetProcessHeap(), 0, Description); + RegCloseKey(hKey); + return FALSE; + } - RegQueryValueEx(hKey, - _T("Description"), - NULL, - NULL, - (LPBYTE)Description, - &Size); + item.pszText = Description; + item.iSubItem = 1; + SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); - item.pszText = Description; - item.iSubItem = 1; - SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); + HeapFree(GetProcessHeap(), 0, Description); + } + else + { + item.pszText = '\0'; + item.iSubItem = 1; + SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); + } /* set the status */ @@ -106,8 +157,87 @@ RefreshServiceList(VOID) item.iSubItem = 2; SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); } - } - } + + /* set the startup type */ + + dwValueSize = sizeof(DWORD); + if (RegQueryValueEx(hKey, + _T("Start"), + NULL, + NULL, + (LPBYTE)&StartUp, + &dwValueSize)) + { + RegCloseKey(hKey); + return FALSE; + } + + if (StartUp == 0x02) + { + LoadString(hInstance, IDS_SERVICES_AUTO, szStatus, 128); + item.pszText = szStatus; + item.iSubItem = 3; + SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); + } + else if (StartUp == 0x03) + { + LoadString(hInstance, IDS_SERVICES_MAN, szStatus, 128); + item.pszText = szStatus; + item.iSubItem = 3; + SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); + } + else if (StartUp == 0x04) + { + LoadString(hInstance, IDS_SERVICES_DIS, szStatus, 128); + item.pszText = szStatus; + item.iSubItem = 3; + SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); + } + + + + /* set Log On As */ + + dwValueSize = 0; + if (RegQueryValueEx(hKey, + _T("ObjectName"), + NULL, + NULL, + NULL, + &dwValueSize)) + { + RegCloseKey(hKey); + return FALSE; + } + + LogOnAs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize); + if (LogOnAs == NULL) + { + RegCloseKey(hKey); + return FALSE; + } + if(RegQueryValueEx(hKey, + _T("ObjectName"), + NULL, + NULL, + (LPBYTE)LogOnAs, + &dwValueSize)) + { + HeapFree(GetProcessHeap(), 0, LogOnAs); + RegCloseKey(hKey); + return FALSE; + } + + item.pszText = LogOnAs; + item.iSubItem = 4; + SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item); + + HeapFree(GetProcessHeap(), 0, LogOnAs); + + RegCloseKey(hKey); + + } + } return TRUE; }