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_YES
, szStatus
, 128);
153 item
.pszText
= szStatus
;
155 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
159 /* get vendor of service binary */
161 if (!QueryServiceConfig(hService
, pServiceConfig
, 0, &BytesNeeded
))
163 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
165 pServiceConfig
= (LPQUERY_SERVICE_CONFIG
) HeapAlloc(GetProcessHeap(), 0, BytesNeeded
);
166 if (pServiceConfig
== NULL
)
169 if (!QueryServiceConfig(hService
, pServiceConfig
, BytesNeeded
, &BytesNeeded
))
171 HeapFree(GetProcessHeap(), 0, pServiceConfig
);
175 else /* exit on failure */
181 memset(&FileName
, 0, MAX_PATH
);
182 if (_tcscspn(pServiceConfig
->lpBinaryPathName
, _T("\"")))
184 _tcsncpy(FileName
, pServiceConfig
->lpBinaryPathName
, _tcscspn(pServiceConfig
->lpBinaryPathName
, _T(" ")) );
188 _tcscpy(FileName
, pServiceConfig
->lpBinaryPathName
);
191 dwLen
= GetFileVersionInfoSize(FileName
, &dwHandle
);
194 lpData
= (TCHAR
*) HeapAlloc(GetProcessHeap(), 0, dwLen
);
198 if (!GetFileVersionInfo (FileName
, dwHandle
, dwLen
, lpData
)) {
199 HeapFree(GetProcessHeap(), 0, lpData
);
203 if (VerQueryValue(lpData
, _T("\\VarFileInfo\\Translation"), &pvData
, (PUINT
) &BufLen
))
205 wCodePage
= LOWORD(*(DWORD
*) pvData
);
206 wLangID
= HIWORD(*(DWORD
*) pvData
);
207 wsprintf(szStrFileInfo
, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage
, wLangID
);
210 if (VerQueryValue (lpData
, szStrFileInfo
, (LPVOID
) &lpBuffer
, (PUINT
) &BufLen
)) {
211 item
.pszText
= lpBuffer
;
213 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
216 CloseServiceHandle(hService
);
219 LoadString(hInst
, ((pServiceStatus
[Index
].ServiceStatusProcess
.dwCurrentState
== SERVICE_STOPPED
) ? IDS_SERVICES_STATUS_STOPPED
: IDS_SERVICES_STATUS_RUNNING
), szStatus
, 128);
220 item
.pszText
= szStatus
;
222 SendMessage(hServicesListCtrl
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
227 HeapFree(GetProcessHeap(), 0, pServiceStatus
);
228 HeapFree(GetProcessHeap(), 0, pServiceConfig
);
229 HeapFree(GetProcessHeap(), 0, pServiceFailureActions
);
230 CloseServiceHandle(ScHandle
);