36bd3ce2485565f55d125975fb793eafdc214119
[reactos.git] / reactos / subsys / system / msconfig / srvpage.c
1 #include <precomp.h>
2
3 HWND hServicesPage;
4 HWND hServicesListCtrl;
5 HWND hServicesDialog;
6
7 void GetServices ( void );
8
9 INT_PTR CALLBACK
10 ServicesPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
11 {
12 LV_COLUMN column;
13 TCHAR szTemp[256];
14 DWORD dwStyle;
15
16 switch (message) {
17 case WM_INITDIALOG:
18
19 hServicesListCtrl = GetDlgItem(hDlg, IDC_SERVICES_LIST);
20 hServicesDialog = hDlg;
21
22 dwStyle = SendMessage(hServicesListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
23 dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
24 SendMessage(hServicesListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
25
26 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
27
28 // Initialize the application page's controls
29 column.mask = LVCF_TEXT | LVCF_WIDTH;
30
31 LoadString(hInst, IDS_SERVICES_COLUMN_SERVICE, szTemp, 256);
32 column.pszText = szTemp;
33 column.cx = 200;
34 ListView_InsertColumn(hServicesListCtrl, 0, &column);
35
36 column.mask = LVCF_TEXT | LVCF_WIDTH;
37 LoadString(hInst, IDS_SERVICES_COLUMN_VENDOR, szTemp, 256);
38 column.pszText = szTemp;
39 column.cx = 200;
40 ListView_InsertColumn(hServicesListCtrl, 1, &column);
41
42 column.mask = LVCF_TEXT | LVCF_WIDTH;
43 LoadString(hInst, IDS_SERVICES_COLUMN_STATUS, szTemp, 256);
44 column.pszText = szTemp;
45 column.cx = 70;
46 ListView_InsertColumn(hServicesListCtrl, 2, &column);
47
48 GetServices();
49 return TRUE;
50 }
51
52 return 0;
53 }
54
55 void
56 GetServices ( void )
57 {
58 HKEY hKey, hSubKey;
59 DWORD dwSubKeys, dwKeyLength;
60 DWORD dwType, dwDataLength;
61 size_t Index;
62 TCHAR lpKeyName[MAX_KEY_LENGTH];
63 TCHAR lpSubKey[MAX_KEY_LENGTH];
64 TCHAR DisplayName[MAX_VALUE_NAME];
65 TCHAR ObjectName[MAX_VALUE_NAME];
66 TCHAR lpServicesKey[MAX_KEY_LENGTH] = _T("SYSTEM\\CurrentControlSet\\Services");
67 LV_ITEM item;
68
69 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpServicesKey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
70 {
71 if (RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwSubKeys, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
72 {
73 for (Index = 0; Index < dwSubKeys; Index++)
74 {
75 dwKeyLength = MAX_KEY_LENGTH;
76 if (RegEnumKeyEx(hKey, Index, lpKeyName, &dwKeyLength, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
77 {
78 _tcscpy(lpSubKey, lpServicesKey);
79 _tcscat(lpSubKey, _T("\\"));
80 _tcscat(lpSubKey, lpKeyName);
81 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpSubKey, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS)
82 {
83 dwDataLength = MAX_VALUE_NAME;
84 if (RegQueryValueEx(hSubKey, _T("ObjectName"), NULL, &dwType, (LPBYTE)ObjectName, &dwDataLength) == ERROR_SUCCESS)
85 {
86 dwDataLength = MAX_VALUE_NAME;
87 if (RegQueryValueEx(hSubKey, _T("DisplayName"), NULL, &dwType, (LPBYTE)DisplayName, &dwDataLength) == ERROR_SUCCESS)
88 {
89 memset(&item, 0, sizeof(LV_ITEM));
90 item.mask = LVIF_TEXT;
91 item.iImage = 0;
92 item.pszText = DisplayName;
93 item.iItem = ListView_GetItemCount(hServicesListCtrl);
94 item.lParam = 0;
95 ListView_InsertItem(hServicesListCtrl, &item);
96 }
97 }
98 }
99 }
100 }
101 }
102 RegCloseKey(hKey);
103 }
104 }