4 HWND hServicesListCtrl
;
7 void GetServices ( void );
10 ServicesPageWndProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
19 hServicesListCtrl
= GetDlgItem(hDlg
, IDC_SERVICES_LIST
);
20 hServicesDialog
= hDlg
;
22 dwStyle
= SendMessage(hServicesListCtrl
, LVM_GETEXTENDEDLISTVIEWSTYLE
, 0, 0);
23 dwStyle
= dwStyle
| LVS_EX_FULLROWSELECT
| LVS_EX_CHECKBOXES
;
24 SendMessage(hServicesListCtrl
, LVM_SETEXTENDEDLISTVIEWSTYLE
, 0, dwStyle
);
26 SetWindowPos(hDlg
, NULL
, 10, 32, 0, 0, SWP_NOACTIVATE
| SWP_NOOWNERZORDER
| SWP_NOSIZE
| SWP_NOZORDER
);
28 // Initialize the application page's controls
29 column
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
31 LoadString(hInst
, IDS_SERVICES_COLUMN_SERVICE
, szTemp
, 256);
32 column
.pszText
= szTemp
;
34 ListView_InsertColumn(hServicesListCtrl
, 0, &column
);
36 column
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
37 LoadString(hInst
, IDS_SERVICES_COLUMN_REQ
, szTemp
, 256);
38 column
.pszText
= szTemp
;
40 ListView_InsertColumn(hServicesListCtrl
, 1, &column
);
42 column
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
43 LoadString(hInst
, IDS_SERVICES_COLUMN_VENDOR
, szTemp
, 256);
44 column
.pszText
= szTemp
;
46 ListView_InsertColumn(hServicesListCtrl
, 2, &column
);
48 column
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
49 LoadString(hInst
, IDS_SERVICES_COLUMN_STATUS
, szTemp
, 256);
50 column
.pszText
= szTemp
;
52 ListView_InsertColumn(hServicesListCtrl
, 3, &column
);
69 DWORD BytesNeeded
= 0;
70 DWORD ResumeHandle
= 0;
71 DWORD NumServices
= 0;
72 DWORD dwHandle
, dwLen
;
78 TCHAR szStrFileInfo
[80];
79 TCHAR FileName
[MAX_PATH
];
82 LPSERVICE_FAILURE_ACTIONS pServiceFailureActions
= NULL
;
83 LPQUERY_SERVICE_CONFIG pServiceConfig
= NULL
;
84 ENUM_SERVICE_STATUS_PROCESS
*pServiceStatus
= NULL
;
86 ScHandle
= OpenSCManager(NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
87 if (ScHandle
!= INVALID_HANDLE_VALUE
)
89 if (EnumServicesStatusEx(ScHandle
, SC_ENUM_PROCESS_INFO
, SERVICE_WIN32
, SERVICE_STATE_ALL
, (LPBYTE
)pServiceStatus
, 0, &BytesNeeded
, &NumServices
, &ResumeHandle
, 0) == 0)
91 /* Call function again if required size was returned */
92 if (GetLastError() == ERROR_MORE_DATA
)
94 /* reserve memory for service info array */
95 pServiceStatus
= (ENUM_SERVICE_STATUS_PROCESS
*) HeapAlloc(GetProcessHeap(), 0, BytesNeeded
);
96 if (pServiceStatus
== NULL
)
99 /* fill array with service info */
100 if (EnumServicesStatusEx(ScHandle
, SC_ENUM_PROCESS_INFO
, SERVICE_WIN32
, SERVICE_STATE_ALL
, (LPBYTE
)pServiceStatus
, BytesNeeded
, &BytesNeeded
, &NumServices
, &ResumeHandle
, 0) == 0)
102 HeapFree(GetProcessHeap(), 0, pServiceStatus
);
106 else /* exit on failure */
114 for (Index
= 0; Index
< NumServices
; Index
++)
116 memset(&item
, 0, sizeof(LV_ITEM
));
117 item
.mask
= LVIF_TEXT
;
119 item
.pszText
= pServiceStatus
[Index
].lpDisplayName
;
120 item
.iItem
= ListView_GetItemCount(hServicesListCtrl
);
122 item
.iItem
= ListView_InsertItem(hServicesListCtrl
, &item
);
125 hService
= OpenService(ScHandle
, pServiceStatus
[Index
].lpServiceName
, SC_MANAGER_CONNECT
);
126 if (hService
!= INVALID_HANDLE_VALUE
)
128 /* check if service is required by the system*/
129 if (!QueryServiceConfig2(hService
, SERVICE_CONFIG_FAILURE_ACTIONS
, (LPBYTE
)pServiceFailureActions
, 0, &BytesNeeded
))
131 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
133 pServiceFailureActions
= (LPSERVICE_FAILURE_ACTIONS
) HeapAlloc(GetProcessHeap(), 0, BytesNeeded
);
134 if (pServiceFailureActions
== NULL
)
137 if (!QueryServiceConfig2(hService
, SERVICE_CONFIG_FAILURE_ACTIONS
, (LPBYTE
)pServiceFailureActions
, BytesNeeded
, &BytesNeeded
))
139 HeapFree(GetProcessHeap(), 0, pServiceFailureActions
);
143 else /* exit on failure */
148 if (pServiceFailureActions
->cActions
)
150 if (pServiceFailureActions
->lpsaActions
[0].Type
== SC_ACTION_REBOOT
)
152 LoadString(hInst
, IDS_SERVICES_YES
, szStatus
, 128);
153 item
.pszText
= szStatus
;
155 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
159 if (pServiceFailureActions
!= NULL
)
161 HeapFree(GetProcessHeap(), 0, pServiceFailureActions
);
162 pServiceFailureActions
= NULL
;
165 /* get vendor of service binary */
167 if (!QueryServiceConfig(hService
, pServiceConfig
, 0, &BytesNeeded
))
169 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
171 pServiceConfig
= (LPQUERY_SERVICE_CONFIG
) HeapAlloc(GetProcessHeap(), 0, BytesNeeded
);
172 if (pServiceConfig
== NULL
)
175 if (!QueryServiceConfig(hService
, pServiceConfig
, BytesNeeded
, &BytesNeeded
))
177 HeapFree(GetProcessHeap(), 0, pServiceConfig
);
181 else /* exit on failure */
187 memset(&FileName
, 0, MAX_PATH
);
188 if (_tcscspn(pServiceConfig
->lpBinaryPathName
, _T("\"")))
190 _tcsncpy(FileName
, pServiceConfig
->lpBinaryPathName
, _tcscspn(pServiceConfig
->lpBinaryPathName
, _T(" ")) );
194 _tcscpy(FileName
, pServiceConfig
->lpBinaryPathName
);
197 HeapFree(GetProcessHeap(), 0, pServiceConfig
);
198 pServiceConfig
= NULL
;
200 dwLen
= GetFileVersionInfoSize(FileName
, &dwHandle
);
203 lpData
= (TCHAR
*) HeapAlloc(GetProcessHeap(), 0, dwLen
);
207 if (!GetFileVersionInfo (FileName
, dwHandle
, dwLen
, lpData
)) {
208 HeapFree(GetProcessHeap(), 0, lpData
);
212 if (VerQueryValue(lpData
, _T("\\VarFileInfo\\Translation"), &pvData
, (PUINT
) &BufLen
))
214 wCodePage
= LOWORD(*(DWORD
*) pvData
);
215 wLangID
= HIWORD(*(DWORD
*) pvData
);
216 wsprintf(szStrFileInfo
, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage
, wLangID
);
219 if (VerQueryValue (lpData
, szStrFileInfo
, (LPVOID
) &lpBuffer
, (PUINT
) &BufLen
)) {
220 item
.pszText
= lpBuffer
;
222 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
224 HeapFree(GetProcessHeap(), 0, lpData
);
228 LoadString(hInst
, IDS_SERVICES_UNKNOWN
, szStatus
, 128);
229 item
.pszText
= szStatus
;
231 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
233 CloseServiceHandle(hService
);
236 LoadString(hInst
, ((pServiceStatus
[Index
].ServiceStatusProcess
.dwCurrentState
== SERVICE_STOPPED
) ? IDS_SERVICES_STATUS_STOPPED
: IDS_SERVICES_STATUS_RUNNING
), szStatus
, 128);
237 item
.pszText
= szStatus
;
239 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
244 HeapFree(GetProcessHeap(), 0, pServiceStatus
);
245 CloseServiceHandle(ScHandle
);