Create a branch for header work.
[reactos.git] / base / applications / msconfig / startuppage.c
1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/startuppage.c
5 * PURPOSE: Startup page message handler
6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7 *
8 */
9
10 #include <precomp.h>
11
12 HWND hStartupPage;
13 HWND hStartupListCtrl;
14 HWND hStartupDialog;
15
16 void GetAutostartEntriesFromRegistry ( HKEY hRootKey, TCHAR* KeyName );
17 void GetDisabledAutostartEntriesFromRegistry (TCHAR * szBasePath);
18
19 INT_PTR CALLBACK
20 StartupPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
21 {
22 LV_COLUMN column;
23 TCHAR szTemp[256];
24 DWORD dwStyle;
25
26 UNREFERENCED_PARAMETER(lParam);
27 UNREFERENCED_PARAMETER(wParam);
28
29 switch (message) {
30 case WM_INITDIALOG:
31
32 hStartupListCtrl = GetDlgItem(hDlg, IDC_STARTUP_LIST);
33 hStartupDialog = hDlg;
34
35 dwStyle = (DWORD) SendMessage(hStartupListCtrl, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
36 dwStyle = dwStyle | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES;
37 SendMessage(hStartupListCtrl, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
38
39 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
40
41 // Initialize the application page's controls
42 column.mask = LVCF_TEXT | LVCF_WIDTH;
43
44 LoadString(hInst, IDS_STARTUP_COLUMN_ELEMENT, szTemp, 256);
45 column.pszText = szTemp;
46 column.cx = 150;
47 (void)ListView_InsertColumn(hStartupListCtrl, 0, &column);
48
49 column.mask = LVCF_TEXT | LVCF_WIDTH;
50 LoadString(hInst, IDS_STARTUP_COLUMN_CMD, szTemp, 256);
51 column.pszText = szTemp;
52 column.cx = 150;
53 (void)ListView_InsertColumn(hStartupListCtrl, 1, &column);
54
55 column.mask = LVCF_TEXT | LVCF_WIDTH;
56 LoadString(hInst, IDS_STARTUP_COLUMN_PATH, szTemp, 256);
57 column.pszText = szTemp;
58 column.cx = 250;
59 (void)ListView_InsertColumn(hStartupListCtrl, 2, &column);
60
61 GetAutostartEntriesFromRegistry(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"));
62 GetAutostartEntriesFromRegistry(HKEY_CURRENT_USER, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"));
63 GetDisabledAutostartEntriesFromRegistry (_T("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupreg"));
64 GetDisabledAutostartEntriesFromRegistry (_T("SOFTWARE\\Microsoft\\Shared Tools\\MSConfig\\startupfolder"));
65
66 //FIXME: What about HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Userinit
67 //FIXME: Common Startup (startmenu)
68
69 return TRUE;
70 }
71
72 return 0;
73 }
74
75
76 void
77 GetDisabledAutostartEntriesFromRegistry (TCHAR * szBasePath)
78 {
79 HKEY hKey, hSubKey;
80 DWORD Index, SubIndex, dwValues, dwSubValues, retVal;
81 DWORD dwValueLength, dwDataLength = MAX_VALUE_NAME;
82 LV_ITEM item;
83 TCHAR* Data;
84 TCHAR szValueName[MAX_KEY_LENGTH];
85 TCHAR szSubValueName[MAX_KEY_LENGTH];
86 TCHAR szSubPath[MAX_KEY_LENGTH];
87
88 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, szBasePath, 0, KEY_READ | KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS)
89 {
90 if (RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwValues, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
91 {
92 for (Index = 0, retVal = ERROR_SUCCESS; Index < dwValues; Index++)
93 {
94 dwValueLength = MAX_KEY_LENGTH;
95 dwDataLength = MAX_VALUE_NAME;
96 Data = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME * sizeof(TCHAR));
97 if (Data == NULL)
98 break;
99
100 retVal = RegEnumKeyEx(hKey, Index, szValueName, &dwValueLength, NULL, NULL, NULL, NULL);
101 _stprintf(szSubPath, _T("%s\\%s"), szBasePath, szValueName);
102 memset(&item, 0, sizeof(LV_ITEM));
103 item.mask = LVIF_TEXT;
104 item.iImage = 0;
105 item.pszText = szValueName;
106 item.iItem = ListView_GetItemCount(hStartupListCtrl);
107 item.lParam = 0;
108 (void)ListView_InsertItem(hStartupListCtrl, &item);
109 if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSubPath, 0, KEY_READ | KEY_ENUMERATE_SUB_KEYS, &hSubKey) == ERROR_SUCCESS)
110 {
111 if (RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, &dwSubValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
112 {
113 for(SubIndex = 0; SubIndex < dwSubValues; SubIndex++)
114 {
115 dwValueLength = MAX_KEY_LENGTH;
116 dwDataLength = MAX_VALUE_NAME;
117 if(RegEnumValue(hSubKey, SubIndex, szSubValueName, &dwValueLength, NULL, NULL, (LPBYTE)Data, &dwDataLength) == ERROR_SUCCESS)
118 {
119 item.iSubItem = -1;
120 if (!_tcscmp(szSubValueName, _T("command")))
121 item.iSubItem = 1;
122 else if (!_tcscmp(szSubValueName, _T("key")) || !_tcscmp(szSubValueName, _T("location")))
123 item.iSubItem = 2;
124 else if (!_tcscmp(szSubValueName, _T("item")))
125 item.iSubItem = 0;
126 if (item.iSubItem != -1)
127 {
128 GetLongPathName(Data, Data, (DWORD) _tcsclen(Data));
129 item.pszText = Data;
130 SendMessage(hStartupListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
131 }
132 }
133 }
134 }
135 }
136 RegCloseKey(hSubKey);
137 HeapFree(GetProcessHeap(), 0, Data);
138 }
139 }
140 RegCloseKey(hKey);
141 }
142 }
143
144 void
145 GetAutostartEntriesFromRegistry ( HKEY hRootKey, TCHAR* KeyName )
146 {
147 HKEY hKey;
148 DWORD Index, dwValues, retVal, dwType;
149 DWORD dwValueLength, dwDataLength = MAX_VALUE_NAME;
150 TCHAR* Data;
151 TCHAR lpValueName[MAX_KEY_LENGTH];
152 TCHAR Path[MAX_KEY_LENGTH + 5];
153 LV_ITEM item;
154
155 if (RegOpenKeyEx(hRootKey, KeyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
156 {
157 if (RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, &dwValues, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
158 {
159 for (Index = 0, retVal = ERROR_SUCCESS; Index < dwValues; Index++)
160 {
161 dwValueLength = MAX_KEY_LENGTH;
162 dwDataLength = MAX_VALUE_NAME;
163 Data = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, MAX_VALUE_NAME * sizeof(TCHAR));
164 if (Data == NULL)
165 break;
166 retVal = RegEnumValue(hKey, Index, lpValueName, &dwValueLength, NULL, &dwType, (LPBYTE)Data, &dwDataLength);
167 if (retVal == ERROR_SUCCESS)
168 {
169 memset(&item, 0, sizeof(LV_ITEM));
170 item.mask = LVIF_TEXT;
171 item.iImage = 0;
172 item.pszText = lpValueName;
173 item.iItem = ListView_GetItemCount(hStartupListCtrl);
174 item.lParam = 0;
175 (void)ListView_InsertItem(hStartupListCtrl, &item);
176 ListView_SetCheckState(hStartupListCtrl, item.iItem, TRUE);
177
178 if ((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ))
179 {
180 GetLongPathName(Data, Data, (DWORD) _tcsclen(Data));
181 item.pszText = Data;
182 item.iSubItem = 1;
183 SendMessage(hStartupListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
184 }
185
186 switch (PtrToLong(hRootKey))
187 {
188 case (ULONG_PTR)HKEY_LOCAL_MACHINE:
189 _tcscpy(Path, _T("HKLM\\\0"));
190 break;
191 case (ULONG_PTR)HKEY_CURRENT_USER:
192 _tcscpy(Path, _T("HKCU\\\0"));
193 break;
194 default:
195 _tcscpy(Path, _T("\0"));
196 }
197
198 _tcscat(Path, KeyName);
199 item.pszText = Path;
200 item.iSubItem = 2;
201 SendMessage(hStartupListCtrl, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
202 HeapFree(GetProcessHeap(), 0, Data);
203 }
204 }
205 }
206 RegCloseKey(hKey);
207 }
208
209 }